From patchwork Tue Jul 24 06:57:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541347 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 26F6E14BC for ; Tue, 24 Jul 2018 06:57:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 134F21FFB1 for ; Tue, 24 Jul 2018 06:57:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 069BD286E0; Tue, 24 Jul 2018 06:57:31 +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 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 8FE051FFB1 for ; Tue, 24 Jul 2018 06:57:29 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=+rGDWaPDZkEyeHAK/1dQNUKVkm14o/D+V2iIbQnF+Qk=; b=BIzU3y6BuNDeiEzAgFbfeGDoSC 0D1/rM70+DbSYJNnm1ib/OD7WnQjqT/SIm2qUQeQLkmc9xjBLfv80OyrUsObDrrgoq3FV7qWUrvo3 y86UaufD9slUPI2SF28SHpA+7iEIhjxV7bYZMTE5V2A3udf2Hu5UeBLEp4GqVrElM/vzxmQiV3YjJ Q7ILLT4G5gJa6S7QCkF6pXwAip8QdmJejO9I9mc1tvPnHdUcIB5B4KgiRDaio/A/CydNLO44Yklr0 +Z2FuieYY/Tgy8JvkGxAoslABMZAZwhynAS08B8kjdX+er5dqLtij3OhBaLE6pOqK4lGFSOo/D05K ktjYj41w==; 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 1fhrG6-0000yZ-QP; Tue, 24 Jul 2018 06:57:22 +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 1fhrFy-0000tN-K9 for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:57:18 +0000 Received: by mail-pg1-x541.google.com with SMTP id n7-v6so2188801pgq.4 for ; Mon, 23 Jul 2018 23:57:11 -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; bh=BD5KBPTKxdMtpqygaHhbkvkazGjFD66/w/IEI5sq6YQ=; b=KSWf7dB62jD+2CI25qIfV0icHgEzVjhvX+daLfcydF/eeJeFARBKhZvS4pStqBy5zN IxWJ523bWypZMHdzMjDVeh65AD+AYBkRgUZ5NComIcmAXDFWKN+eFozGjPTSK3iG07Zk RBv+0SzD0fMx7hwfVqwmR26FtLw3uiAxqCkSY= 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; bh=BD5KBPTKxdMtpqygaHhbkvkazGjFD66/w/IEI5sq6YQ=; b=jz9DVOxLKcQp8+K4c2cRzgIZH9LLc5p3LfCqvf3fr/giz8jii57nKjjevckDmhkvdH 8Nqc5/YbYeteugeHiLTWN+PiMkVr8z4tKkLA6SryhA7RjLpN/GQyWLeSZFQJOcH3MkCo Jzz/1cokDBtILUPD2KeF8jeECuPiqenCzkARa01AxXG0PFGdgLFH6dsqmtWb9ibbCdD9 PiutS25bOYbjs2xPnyjjNIpSQmzCyyumMhT12IXXdBmhghYxFkuEGYfjpLdLrVpRxaBE b3cp06SvbHfNUnhAeevoApihPKUqeyNaGSvISEOkG/grY9iIy7jG4aagtf5zCW5hPAPr n41g== X-Gm-Message-State: AOUpUlGLyGSa48Q8t6irE/kEYEC8aqhX1VQBz63SUMH4p8+UGJZwm5S4 rC8TG9K28MYu+RRT4mHw3nRc5w== X-Google-Smtp-Source: AAOMgpfZytCmntNk893W3ELT04ScsWkhUGrKTLhbTE5ic9zIxhbPiY1g+r7VQnViBdUAwDcfVlVu5Q== X-Received: by 2002:a63:62c4:: with SMTP id w187-v6mr15035901pgb.55.1532415430908; Mon, 23 Jul 2018 23:57:10 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w81-v6sm21247538pfk.92.2018.07.23.23.57.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:10 -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 v12 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Tue, 24 Jul 2018 15:57:44 +0900 Message-Id: <20180724065759.19186-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235715_672528_2B667455 X-CRM114-Status: GOOD ( 11.35 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 42990676a55e..c81f4a0df51f 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -734,9 +734,11 @@ __SYSCALL(__NR_pkey_free, sys_pkey_free) __SYSCALL(__NR_statx, sys_statx) #define __NR_io_pgetevents 292 __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) +#define __NR_kexec_file_load 293 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 293 +#define __NR_syscalls 294 /* * 32 bit systems traditionally used different From patchwork Tue Jul 24 06:57:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541351 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 37C2514BC for ; Tue, 24 Jul 2018 06:58:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2373F2873D for ; Tue, 24 Jul 2018 06:58:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16B7328740; Tue, 24 Jul 2018 06:58:16 +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 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 B19D32873D for ; Tue, 24 Jul 2018 06:58:15 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=2lpyGd3njXQWO6NaEzM8LSzZb/0StDiNmH2jVwLsPOs=; b=C6GJ9Kj94P+azyvpW6Uva7b6SY tumxcLatf33P4onik9Kik6v7MqSBmi6hKjYEmT3/2TAQrL1+EUdEQeP9T0m2KPEXs66hZQ0nk8fNt 6jhqld2WQNTfWdu73aWaS32O8H9Xy07+aHe+BTMDZSAv0ej9D32J/npmDTKHHITmqfglArDJAMtoo QsFvt+Qnj1LE0h5d0aPsV48ZGnjvxcuBmPWU+r5anKoHett8PQS38hogBZwztM0RtZSqprWdlXpgY Mqus4o5/ARC4NjHjfc4yHzUt3ztdMV/4vJc/78TKXewSdPfZtqYH5ej2CSvmVlLg+pohITmRg8GSd jrhHAl5Q==; 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 1fhrGn-0001oS-Uk; Tue, 24 Jul 2018 06:58:05 +0000 Received: from mail-pl0-x229.google.com ([2607:f8b0:400e:c01::229]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrGF-0000wl-CJ for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:57:36 +0000 Received: by mail-pl0-x229.google.com with SMTP id s17-v6so1326467plp.7 for ; Mon, 23 Jul 2018 23:57:21 -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; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=cxgjVzY3MX0woauM2mQ0DdwelCWnuhJ3LX8wat27L/s2w/g2I5byL+3gKHF6y9iFVA HSpNiUSQsbulmADcHfeQ3KBclHJadIajI1bNqZwznx3JvdbU0PnhNY6dpzou+JJTZLpa fFvq3a6BiD/aBwwtqo4dCjGCLHdqEb59HY8pY= 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; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=kQznQND0mwnP4N1gp1W7WLIDAkgthlCKwo/0pU6cNrorSOnnXgrbLcCNTg9O/U6ZAN JHpu+viPmsc2VFmUuCrDAMvmd15NY0f6t7XLO1eHKVriE2uBAK6D4wApyBbO4LL3l/j9 R3l8vACi4cSGZ9KVOTJGOzC7QUHjsRdohuDrLvUcBqY+qrxSXwICNYqr9OvN97NoZJD2 O81Tj2wuxYPq05NHv/kub8/pAXu6MaSBDTfrK9t6FOt4ymEcUQCUsFiLXZZ03jXAzu5k Y8CgKFG6BAfEIELK0fS9vdi5+LXw/MygzWYFFanH8bboM2w81TWM4E0mk1eqmQFxu4ga Lhsw== X-Gm-Message-State: AOUpUlFqQgOZ/Vk5iBfV7lASVZ2ftPgMtq4UvUVEifCvGLx6td3nlq0O 7odu1KubxT9TjB8AV8f/pfthWA== X-Google-Smtp-Source: AAOMgpccEHK0X4LG2sCssROyMS3DTku3sl+Su6+x8gDwvPTU9oeupQxycIsl3XZpnapXnzG5Z/MvIw== X-Received: by 2002:a17:902:8f96:: with SMTP id z22-v6mr15898099plo.190.1532415440585; Mon, 23 Jul 2018 23:57:20 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f126-v6sm15721472pgc.88.2018.07.23.23.57.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:20 -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 v12 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Tue, 24 Jul 2018 15:57:45 +0900 Message-Id: <20180724065759.19186-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235731_948810_49030F4F X-CRM114-Status: GOOD ( 12.67 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 Tue Jul 24 06:57:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541369 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 D263917FD for ; Tue, 24 Jul 2018 07:11:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B347B28706 for ; Tue, 24 Jul 2018 07:11:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B154C287EF; Tue, 24 Jul 2018 07:11:34 +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 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 3D79E287D5 for ; Tue, 24 Jul 2018 07:11:34 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=+xCdLHad/arsGx5k3/f0rxWy33jDVw47Fy349WezrK8=; b=D+02sVopPLL6kikS+LuYDPnTOa 0vtOolZQlbnObrbn6BT38FbCd4BBkVJgORGM+5nhKvmYw2DApiEfGcnPMh1Ssw6QXZC9ApymZV59G +qiHvBDLyYmtDACdF2hGOouwYzuRekse61olPopVjv6JV3aqIZKHIaQUE7Q2sk3JNr6LvCc87lljM oUjjiSfICvUAryZy1MTsZvuqCwkBpEZ/F+HRTgsGlSvgNq5TnN5TmXuYaUrbythKAAC/mBx6ydAe/ +YfMdPhMViclsCYfLmtzFr+K5Vk01C3k/wzEESyetb+1v66lCLAdOJHhQyzgycNfrRchWfdhYrLm0 EU0IylPA==; 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 1fhrTn-0001DH-4p; Tue, 24 Jul 2018 07:11:31 +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 1fhrGO-00019x-Pw for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:57:46 +0000 Received: by mail-pf1-x444.google.com with SMTP id b17-v6so624366pfi.0 for ; Mon, 23 Jul 2018 23:57:30 -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; bh=8ScyWDBSkpDCeiO9xWIrh9E1Li1NS358S3v+0v5j+T0=; b=iiggbw/YJZIAmCl7wpn67Ovdkz+pycG2Mg51R/BAaen71ZB0eRXijPEyRgy/mq7wcd vZuBl7F5EF5rXfpH1vpV/gyllE0ooG8GMxvKSqC0uAnU8aq9M42TGFGK7DAI3m1gVdH5 IQJsH+l9kVW4XYYkiCKC0zQ/frf8WjM9ggA+s= 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; bh=8ScyWDBSkpDCeiO9xWIrh9E1Li1NS358S3v+0v5j+T0=; b=alKfyoR7P2aWIEoygUwNdiEdIVRSWyh8iu45sL9yMCJZVfCg6oAiyWLJ8xk8VESTpv g6UGYqttyPRZaFquNeg4AXaYadS8jR3LqQuQqA67q/gHvREjSKtETBIV5e+Zcj7xPNUD n0Nr0i7EUARwUTH4bYEnqRMd9vYz9MTFZqULNzrMasWNQLosaGHQeyMufikwvqy6XUvW +yzmPVPNBC5yHPDJ/AuVBJYecqwrdb3n10tXZdaKjdj7+X9sP8WY7ydMaZd9qsi8u2nu jPmzgmrprL0jUJx/RWb5+zUN9HMizwIRgZd8jcZXwfpKmKns4cauR9Zimk+AgsrgN2Pr 90/Q== X-Gm-Message-State: AOUpUlFmKOVkNn9NZ1UjusXRTeE5MyBZrw4HWrwxas+S2/v/0Y2H+F5s hew4mYy1MT63OvvVjvHuH5imWw== X-Google-Smtp-Source: AAOMgpd1sndZWCunzrA9HLAAoRE8DF3myXLtZcMYvG+4FiARYJJehM9j7fcL1BGeIM4XeNi2dZC+2A== X-Received: by 2002:a62:3601:: with SMTP id d1-v6mr16421214pfa.41.1532415450265; Mon, 23 Jul 2018 23:57:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z19-v6sm2465351pgi.33.2018.07.23.23.57.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:29 -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 v12 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Tue, 24 Jul 2018 15:57:46 +0900 Message-Id: <20180724065759.19186-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235741_194325_4D81936E X-CRM114-Status: GOOD ( 13.98 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He Reviewed-by: Philipp Rudo --- arch/s390/kernel/machine_kexec_file.c | 10 ---------- kernel/kexec_file.c | 4 ++++ 2 files changed, 4 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/kernel/kexec_file.c b/kernel/kexec_file.c index 63c7ce1c0c3e..bf39df5e5bb9 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) + return 0; + ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; From patchwork Tue Jul 24 06:57:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541375 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 F40B217FD for ; Tue, 24 Jul 2018 07:13:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB4CA28744 for ; Tue, 24 Jul 2018 07:13:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE96C2874F; Tue, 24 Jul 2018 07:13:35 +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 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 330FC28744 for ; Tue, 24 Jul 2018 07:13:35 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=e77l5opCVUx9K89OIt4xlvQiNZkaB6X7nCey1USSsDI=; b=gHMKB0UBR9j5Hgi6i8rrr7IZY1 aMx1AFMQktlnhqXsujjE3kH8qDeim9NWAwdk10EuqGytmmH4qoSZTIrcSzcrGYHa9DI6ZFXMxP0Uq ezN6dVIzlHsKTPt8ZgrrEheeLXYEdSp5R8OMGYE3W59wE8FI6fdC9sg9s3pOBMohQDuc+8F7JnpXl 5IxGWYetTuU2kLHxsug3YoHEbvjVlSddQPqjrPJ9jB0Cjcss82JCWAPuDKgJCudU+Qy+rtL1AO8jO nFG6OXjzdQsNeHnTt00cc2M/7TsmDtTZsZ5EWcC2X4wdoVS2PyGy6TuQT8qF7kA2gfuVBMFpjrKhJ Zd+VVd4w==; 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 1fhrVj-0001yu-IK; Tue, 24 Jul 2018 07:13:31 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrVg-0001hV-W2 for linux-arm-kernel@bombadil.infradead.org; Tue, 24 Jul 2018 07:13:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=n4HcoP+WTvAeoAsFm19FwxSxHpLoU20/JAibgnpWWF0=; b=cTO3ntA+1doIGWUP21fit4mUE R/97b5VFMU6aWDn32zVnP0/4dW82wHqhCYazgyf5en+4BBTVtYks7agtFUjemtMRK3d+jRpIG/9qs Onp+u1zy36jmpILk9HvOvr3q8eDwh9PUcDkFPbziiYDn4P/eCWIE0twCpNPeQBTqOVFzj1ttllD+5 I+CsPRvn8vlxXNY1PphEigmNQVcesHhDr0c5DV+ooYDFhcs82RS4QaRB7at8R0/15ROWVuWckfuHN sI0rFRV3s3RKHWt/U51Dtoucht8jkbYN3f+dNO8cnhxihjg3UxaPUcmhvTUoUXVx+1XHGtIjnU15P lUaY0vU7Q==; Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrGb-0004gJ-Tx for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:57:57 +0000 Received: by mail-pl0-x244.google.com with SMTP id m16-v6so1323878pls.11 for ; Mon, 23 Jul 2018 23:57:40 -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; bh=n4HcoP+WTvAeoAsFm19FwxSxHpLoU20/JAibgnpWWF0=; b=Wryl1us2gO6DrmNmMtIVXaVWLAGWibT0SJZxo5ygw9YEyEXizgGaX/hljMl37iwOxL O9fQo9u5/A8HDRUbRPleQc50NZxrE901vGIOJT7LTwof20aDo1HBDWb+BAxzXeT/e2YC +iwCjOzQGUwiEKvwOzW1iq4kUFe9chIOTcI9I= 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; bh=n4HcoP+WTvAeoAsFm19FwxSxHpLoU20/JAibgnpWWF0=; b=a2NY9DaOhsxaHMHAKWrTo4pg2hx3hfhLLDDU0BP8tdxHpdQEciOABWk/xcDGwu4Lqw qQQ11EdWdhkWfwc/i732G1gOYXAbnoL1pXMAlBtyaQl9pwXoSMYpLeO19cfnSSTV86kZ ae0I1rtLIbNssDRJkVNDGqtlZgo+Jy1QSY0Ug7PUXXnMrc3oV3U349sxLz95Gv2rzxhw /oFLmbSCMSOf36bFrnzSxhnLBrfIGhKL/8F9H2zrg90T9pkGk+vCncKUWbaA6uL3PsQB rQzNcZwP6nyU8R+B1pwxAyFkI8/zQA0fPTRAdE5cdfOvurRDxEmYNlOvbDBfsyRojfVK /B9Q== X-Gm-Message-State: AOUpUlGSwkxpragiigOgewSYUXrlg1BUmWewt7ZbsDIBTWDXMia04p8k O9dUJcaoDr0TlrQ6lyTEYSDPoA== X-Google-Smtp-Source: AAOMgpfPRDZGOtMwp/bj9Pcv2NkubVPqyL3Y9Z/2bWG3zCO1TNx2ZYCu3nCAOKqK+WTPT05sMEeRbA== X-Received: by 2002:a17:902:e3:: with SMTP id a90-v6mr16099122pla.227.1532415459458; Mon, 23 Jul 2018 23:57:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 14-v6sm17684945pft.93.2018.07.23.23.57.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:38 -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 v12 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Tue, 24 Jul 2018 15:57:47 +0900 Message-Id: <20180724065759.19186-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180724_075754_219900_F1E241D2 X-CRM114-Status: GOOD ( 25.36 ) 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, AKASHI Takahiro , james.morse@arm.com, "Eric W. Biederman" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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(). kexec_walk_memblock() will not work for kdump in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse Acked-by: Dave Young --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 ------------------- include/linux/kexec.h | 2 - kernel/kexec_file.c | 58 ++++++++++++++++++++- 3 files changed, 56 insertions(+), 58 deletions(-) diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index 0bd23dc789a4..5357b09902c5 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 49ab758f4d91..c196bfd11bee 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -184,8 +184,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 bf39df5e5bb9..2f0691b0f8ad 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,7 +560,7 @@ 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, +static int arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(struct resource *, void *)) { if (kbuf->image->type == KEXEC_TYPE_CRASH) @@ -538,7 +588,11 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) if (kbuf->mem) 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 = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Tue Jul 24 06:57:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541503 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 77D2D14E2 for ; Tue, 24 Jul 2018 07:54:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 674932871A for ; Tue, 24 Jul 2018 07:54:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5903D28776; Tue, 24 Jul 2018 07:54:23 +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 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 DF4EB2871A for ; Tue, 24 Jul 2018 07:54: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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=9dAlmITsvpeIeG16oqlCApTA3/HN5UcM9ghwbTVTyO0=; b=Rn0+ijjslHU7H9s6/58z3C/aau 2xjvE51ds53zPqs71FknFrtWPUeOjz1In7nEYxC67pWEXE/tybxpPA4qX7ZNZR9/3qn5sDo3QFIUF eL0yKiMeBlE4JapFD38O5MT5ExiazCjEd6TTW6hxE6qz8A4xbLxG3ge6o6ssaNQCW5c4xwJ5DtJGt lEUgE1M3c+kMNqtsLp3PfNNOXcuj/MjME5zIlbOFvVg7lNNZwJRBoPSpkxpsbsBbUV0o8BF48Rce+ Itlif7p6+4tMBJ4yL7GlkZpD6IId2eMrDe+DOgor31gz7N8W50bnFAxbszvuk6TlCZ3FN4kq5pFh+ zUoreNoA==; 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 1fhs9D-0001kB-8g; Tue, 24 Jul 2018 07:54:19 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhs8H-0000PI-Gk for linux-arm-kernel@bombadil.infradead.org; Tue, 24 Jul 2018 07:53:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qX+9ZLjYleTqiYTR/9AsWjndzTTMAgGfRwkaazjqic0=; b=XgQGbhMR7ZZAAhI+/KE2dzmif 5g9Y3mAp9MSClVItZIzEUjWYf2hwLmwyqFWXYufFI6GgGAIBi7e1mzZitxPC0gNK/tHn7mchpeaym 1G9sUEt0Ey6hhTJAKrcqRZDuAY9+MrAI2KObv52sdnQqIH9nr5EG/DKX2CPS8mCvQsIJRUyNMyLi6 IhXpGmU+Jgx4LYxqH9hIferB2FuOv3qOO0SKVZhtAFM5xa+IVu/XFgt/Zzh6svbZdg3xEv0EU6PuB pdpPnY18LKYi8ACJaj43ZAIumFMRFBxmnaXrn0hoPabgRuL8jSWGsYRUs7WcKdxKXW9cLvKI4hZAi CWyRSpUYA==; Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrGm-0005bE-VH for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:58:05 +0000 Received: by mail-pf1-x444.google.com with SMTP id k19-v6so624015pfi.1 for ; Mon, 23 Jul 2018 23:57:54 -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; bh=qX+9ZLjYleTqiYTR/9AsWjndzTTMAgGfRwkaazjqic0=; b=Gjx6vY7EwRTKIrVY9J55sUQ34HHFlTe4FmpRadgter9yKeBuzeehOo01GQ1nzj7rQx IZZnGZQGxgEy+Nyb24xy4H0OmFFN3qMUY2CgDgPuxd6PM27plx5Ier0qF4WBMg74Y3nR 3/P+rUjJOAnix3Ymmp41EkC6E95ZGNa/i+SuY= 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; bh=qX+9ZLjYleTqiYTR/9AsWjndzTTMAgGfRwkaazjqic0=; b=oAhy7whpLhTE6mnI4rLxyoawlWyOj6zMlMGWHFezwItufHiaoX++5QreMHt2IjW6eN n17kf8m5GItOQffdyp6iXhxm8+0ZHyTkeWxtHVU1FYU7s0oUtSk79D7mB3RjzSeyP9ia dw/Mjs1OupSiirvP60KN93aFUmQcxQqpaaM/qjaIPLtgRcT99BBRfJiYha7loPFNxcjI gRU4QaLf8wNMJI0I6J2PxGRA0nHzH2g+zuo34UwH0X2YQesMjGhCY1YJKi5yPHuaTTlx 4fNXHuP2SK8wvmHVD9L1Zq3H5+Ow79qbpzuLAE+d73zuBycHpfEo4/ahOflLgCQ7mELI bKHA== X-Gm-Message-State: AOUpUlF5F5C/66wAT1eB9RRLRtVynkYS1NMkYZNuLHiRibkBtPtXfplr yAevW3S4mSIGV89GpL2F5Nyb8g== X-Google-Smtp-Source: AAOMgpcwmDaP8xLQtGFckK/ZRQpKdN3DRNQMvSg+7bcNGgWpnLXaKTUCf/2WglReEBbUlrEb8a4cew== X-Received: by 2002:a63:f756:: with SMTP id f22-v6mr14890781pgk.289.1532415472243; Mon, 23 Jul 2018 23:57:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u185-v6sm16092326pfu.134.2018.07.23.23.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:51 -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 v12 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Tue, 24 Jul 2018 15:57:48 +0900 Message-Id: <20180724065759.19186-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180724_025805_039726_D536792D X-CRM114-Status: GOOD ( 14.62 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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. Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- kernel/kexec_file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 2f0691b0f8ad..bb23f9280a7a 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -511,6 +511,9 @@ 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, &mstart, &mend, NULL) { From patchwork Tue Jul 24 06:57:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541353 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 9A96014BC for ; Tue, 24 Jul 2018 06:58:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 884952873D for ; Tue, 24 Jul 2018 06:58:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BAB928740; Tue, 24 Jul 2018 06:58:50 +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 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 15EE72873D for ; Tue, 24 Jul 2018 06:58:50 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=V6z1jR+HAfpJzHIG5P/KpDn6+35qCd2LfkIslVjlFKg=; b=Mj8vd9NXOfUa7Y2EJ8Aps9J4se E0J4T0+KwVKIg3Q0qcsjFTikfGenTljjlbF2MY/pRbelyAfA2aNzP2PFYm8C49/SxL+L2/c6J+Cwy KbnTBW18sfDQ1tuMpuY0M1sVv/nvuA7ENO+xnOkvq3jEQud5+45XklmNGfVkk3nLCSN0AOVb+6Ogu Gsffcc2BoNevm4Qpb4iM+CNz2Ktd1LWtqjpqNpC4ArHCYLgkt9Ih+ttjg3Qpf6AGLXKvQWcWsdXbq DgXj2sD/KAqzsGobRjeWOrVYFEyw9C8kIIlGXnEt9fZ254y42K5zolLoq19hMpLvntc2PJIN26DEg QzPGentQ==; 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 1fhrHR-0002RA-E8; Tue, 24 Jul 2018 06:58:45 +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 1fhrGt-0001nh-O6 for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:58:39 +0000 Received: by mail-pf1-x444.google.com with SMTP id x17-v6so623300pfh.5 for ; Mon, 23 Jul 2018 23:58:01 -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; bh=fLowSY6mJuob0j2AasYwzHifbnb4+IvdIDuIYU6ROck=; b=BK5+jtRPvI4T2uWUEa4FbqGVKf2792r0k4n+769No4hC++DANnRliJes3gizzPJwz4 XjaqadmeavGNPkIDA5kKCeBd7DXiKCqV75rtFjOaPqX1QZ+/kpw7a6W+noWagVqOaIMA MOH7RjRGCSSqcKJwDZld3rmTYpq4o1GNfz+4Y= 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; bh=fLowSY6mJuob0j2AasYwzHifbnb4+IvdIDuIYU6ROck=; b=an6xV4OwmIY+J2UGgyIn6nAjw7jnzJc97W5ajQyela/XE8geBsCLBmWOPosJ9y6PY2 nQVEtMiPENjJ4j9YbpQuKoG+lepwvGpLzKLKWDOyYRe4hjFoiBHshgK7HE6LkctwNyRI GL+jwCRdEgRxnq9lnPfYn/JAnPhhRP6j1oO6JXQWMtZfUtaBq1pRMqYV+AROxhvxMUcw 7QwwcDVTEuIvqhky1puWQ6iHrWjzy1SBRSCZTWI7K3AAAQSY8ygAHYdcJS7qJ+1eOOHm +lf6YllOf8cnsZfHXlsEtMTRuR6UpGxs8dtCmb4pSEE5HIAPaTG8qmB8DdAmasoiKXqq gu1w== X-Gm-Message-State: AOUpUlFo4SpXabidGsHq6j45P4kIxnPBJGXGBGq5Km1+mxGtxtRW/5yd C+2NRycpcm0IHrchc4I+chS4vA== X-Google-Smtp-Source: AAOMgpfwP54l4LD8bGGYN376t7ylPgvSG7StD1sgvy1IhPxnqA44U+YHr9eqEybBTEFZP67W5T69cg== X-Received: by 2002:aa7:84c2:: with SMTP id x2-v6mr16328237pfn.220.1532415481321; Mon, 23 Jul 2018 23:58:01 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a20-v6sm13998713pfi.124.2018.07.23.23.58.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:00 -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 v12 06/16] of/fdt: add helper functions for handling properties Date: Tue, 24 Jul 2018 15:57:49 +0900 Message-Id: <20180724065759.19186-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235812_223448_3943D590 X-CRM114-Status: GOOD ( 13.86 ) 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, AKASHI Takahiro , Rob Herring , james.morse@arm.com, Frank Rowand , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 --- drivers/of/fdt.c | 62 ++++++++++++++++++++++++++++++++++++++++-- include/linux/of_fdt.h | 10 +++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 6da20b9688f7..f7c9d69ce86c 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 @@ -537,8 +538,8 @@ void *of_fdt_unflatten_tree(const unsigned long *blob, EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); /* Everything below here references initial_boot_params directly. */ -int __initdata dt_root_addr_cells; -int __initdata dt_root_size_cells; +int dt_root_addr_cells; +int dt_root_size_cells; void *initial_boot_params; @@ -1330,3 +1331,60 @@ late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ + +bool of_fdt_cells_size_fitted(u64 base, u64 size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((dt_root_addr_cells == 1) && (base > U32_MAX)) + return false; + + if ((dt_root_size_cells == 1) && (size > U32_MAX)) + return false; + + return true; +} + +size_t of_fdt_reg_cells_size(void) +{ + return (dt_root_addr_cells + dt_root_size_cells) * sizeof(u32); +} + +#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) +{ + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + buf_size = of_fdt_reg_cells_size(); + prop = buf; + + fill_property(prop, addr, dt_root_addr_cells); + prop += dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, dt_root_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..9615d6142578 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -37,8 +37,8 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node **mynodes); /* TBD: Temporary export of fdt globals - remove when code fully merged */ -extern int __initdata dt_root_addr_cells; -extern int __initdata dt_root_size_cells; +extern int dt_root_addr_cells; +extern int dt_root_size_cells; extern void *initial_boot_params; extern char __dtb_start[]; @@ -108,5 +108,11 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +bool of_fdt_cells_size_fitted(u64 base, u64 size); +size_t of_fdt_reg_cells_size(void); +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 Tue Jul 24 06:57:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541355 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 A608914BC for ; Tue, 24 Jul 2018 06:59:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 937C32873D for ; Tue, 24 Jul 2018 06:59:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8600028740; Tue, 24 Jul 2018 06:59: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 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 316892873D for ; Tue, 24 Jul 2018 06:59:24 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=M7HskRhvb7uKpaPyMVCFD+L3cPLioPqtP9kERY641aE=; b=afIK5GUlGBY40fI5brlrObBAkr 5ICHgLJry02LGwG1QAyrrStYmZaB7d1IwWmMYskxBcbKfC7+uiywL37u8ZHUUugIQVdqp8usYclGa qNjhOBqK70VxnZsdEKT7AbhKtfhfquc0syGp7S1YBwDzyyX//hNRwzcqONBGmDLQSkEZwdaShX//T uquyf044DjhAnfl7kILKEX2vr/zx9FxZ7Fig1nfpbMubY+Iwy5axka0Mj2Lt7oMsgj5mIfEimIFak zC72YuYBeZJbkm48jSgXC+a/wcWWOXB+gUs/RW9+rKxcFwzQSILuDRyKSXREwsNHsp2dP/REOUntk yd8hnafg==; 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 1fhrHz-0002rm-Ho; Tue, 24 Jul 2018 06:59:19 +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 1fhrH2-0001t1-38 for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:58:41 +0000 Received: by mail-pg1-x542.google.com with SMTP id x5-v6so2190010pgp.7 for ; Mon, 23 Jul 2018 23:58: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; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=C/yqdvKWveGmKVzfCDCnCkBq5NcFX9WA1yra9YOhCwvn9CfIM1fEOdK1zcjJ0ekASY p6+Ufuwksx9ALn1kqyOHJMbrBNTCPm74x4jxrdTj7H+j5bNDIqHPqIEoCE1nYZexUTJ9 EtEADpmliTcPzQlEruISMb1H0icOglJoQlEj8= 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; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=twBemcZC3QDrcGqKuT/uVRGiHCR2CGXEZQj7nKi7Pmm7yKwiLgfiv7JJ9iuIBwxniZ 7sf73wcq2ADicpbRqBDH8gxM7maJ8qQ2oJNMFKQzYY7575kbObpWJdB0H87J7NAIHmLg qojXX7dtZO8MUA+Q/AB42ZNB2XfccawwWVnqgM71G1TKcCJNeXUzgwr3iwphhgYIbIZk ZmVwgciZaRqW7T9NbGHpJTfz/bZjB7Wr/A/JdbWqvJadHQvRcHO1VKDqUYBgS75nwXPv 2/4wFqfHO76cS92D+BWn3pbEnJW3tSDzSqIM+i1Obxj0D/cObwtMWjU+9edSK9f+IWLu l5MA== X-Gm-Message-State: AOUpUlF1eGY0tljJwh6JSaPDpn1ewCJ4/WLzntwxNaobAWGCFFX+sPe7 qfb3DoxWL324z26v58NSnF+S4gpPPj8= X-Google-Smtp-Source: AAOMgpcifmCLOo/grYLjGB8iAL1KUz1Ig/0vFwWtz1djsomngxlwEx01Gjj8jnGz7Fd7mWCUiPhIWg== X-Received: by 2002:a62:e00a:: with SMTP id f10-v6mr16513182pfh.208.1532415489663; Mon, 23 Jul 2018 23:58:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t14-v6sm11418710pgu.0.2018.07.23.23.58.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:09 -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 v12 07/16] arm64: add image head flag definitions Date: Tue, 24 Jul 2018 15:57:50 +0900 Message-Id: <20180724065759.19186-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235820_545277_09F9B6BE X-CRM114-Status: GOOD ( 12.69 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 Tue Jul 24 06:57:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541501 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 E17B6184F for ; Tue, 24 Jul 2018 07:54:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3EFE2871A for ; Tue, 24 Jul 2018 07:54:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C78D628776; Tue, 24 Jul 2018 07:54: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 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 71F542871A for ; Tue, 24 Jul 2018 07:54:11 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=AH82xejSFq8HIgX/nWs4sY6xm75sFioCSxYC3DPXxNg=; b=qH/E2+sG97rzp1lY+V8j4bPz30 qS2OXeXO2sDLeLPRDx6sPlwMiE9b31WaZNkqCuNHqquZZzRxwqsR6pUvqODu8LIAF7ZE5WHLvK0Nl 1hl9nclU19Z5Va8u484wmQg0X2ivpuWNlVdUuJSwM/rdLCmHi2Zpb0bx4La4h/4ZcYxCExLaBSRgf 8BL/hjIXJI1Ob1YcTUZvnxadiSIfy34QcFqaFzTOLB1sZcBclhL1yxCGxg/JB1ErrsBlPAlJ4O834 YPbk/fZjGVGK/d7VOjH9nIYpwF34v1CxinJz/jpFM9iUuDs3zAhtPB0MkLBHF402623V5HDL3hA6j 7ddITf4Q==; 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 1fhs90-0001UK-3X; Tue, 24 Jul 2018 07:54:06 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhs8F-0000PI-UG for linux-arm-kernel@bombadil.infradead.org; Tue, 24 Jul 2018 07:53:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=dU65SCmUZ3bEmw10h/w/gVUby C4Eu3NIx5/Fk30kgmcpiAiqCmiYOlLFQ+QSKI8cmsV0YUc9X06MfxchLW+iACI4NseVibCshQMOYq gdExZWV74hSxBKkVy/reNqgXpGRvn2CzgloZ+7bGFI2UEAwF+MqdNStxj6YNs+7xGg7DmDhF/ZVRa fig3AQndHIcd9qN84cbqan4YxBvqOi7YjPjv4vQsFFAe6Krh/lL20Tjtfnrb64WK2Tr37lqCbO5kH D6w+Mc/pRqZVYDrBucnAqvUv5+RGQ/FxNNxH7/iU/UywKG9+v4iUGikzJSKUjthTYlNzpGanwoZVN 7s+q4+Uvg==; Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrHA-0005cs-0F for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:58:28 +0000 Received: by mail-pg1-x543.google.com with SMTP id f1-v6so2177861pgq.12 for ; Mon, 23 Jul 2018 23:58:20 -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; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=IZCAvraVKXBMSrt+LprXRPa8TzsWBujFGzK9iGYEfcaNi9ch0BExwJB2bhWlPjxxw5 0RxjkbJ0RyPgwkU8AJzqEAb+Wilqoedt05oJtDRJAm0xODSkBfBlNNDzb6/9iqf2Xea6 ccl7Lfh3ELIhGGhvF4npOmcNsTPh8kJ81C+HI= 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; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=pEFBDe7ECK7DKrqsUL5VXOPPjl4pmY0I/QSAK1isCNV6tRog48pYoXCnu4hbJOGHwE oplsJsXnMPARtttsIeA7mAwwHxaWz1tx/ldTCjkXdYHqPvtAm0COxpHjz6cDowLp8L74 plCPwTtIdmUyGAD3q5hTfbUc8tDB8Y4/HOu9y69Uh3SnhuJXNo9A7oCuSr21AJAvy0Xa GqbMidMsX9jTDBsXKU3OBIjJH0uLZofU7+MAySJhw4+Op5bbpQwVscAJMxOeCbvXqHMi ZMEx4cA1LuAzkdvQYIcEkAMtnY8pyM+/sA0D4nKeKFziM/AgsUvmEG/lsV4s7WFID9ee Ywcg== X-Gm-Message-State: AOUpUlEnYMXtqM5GNAd4fRcPMpMKnT76itMXatzqgJEUwuL8vQAJD0yp JYeaQZw22Evq2ERa/4Mts0muIQ== X-Google-Smtp-Source: AAOMgpeTka3r2VkaE8A4nOw6byWcsgyhZRfyzVMrHXe+TqVMyReY7+zdj63kRyqCRVdniZFbYXO3SQ== X-Received: by 2002:a62:c0a:: with SMTP id u10-v6mr16375735pfi.43.1532415498607; Mon, 23 Jul 2018 23:58:18 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r19-v6sm15966732pgo.68.2018.07.23.23.58.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:18 -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 v12 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Tue, 24 Jul 2018 15:57:51 +0900 Message-Id: <20180724065759.19186-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180724_025828_179169_1F92C048 X-CRM114-Status: GOOD ( 13.09 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 Tue Jul 24 06:57:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541499 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 DC60014E2 for ; Tue, 24 Jul 2018 07:53:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CED1228773 for ; Tue, 24 Jul 2018 07:53:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C24DA28777; Tue, 24 Jul 2018 07:53:58 +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 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 6423B28773 for ; Tue, 24 Jul 2018 07:53: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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=vYR1uo2/pEv4Br8jnXfGeFFuxJOX9Rf8/VUAXaSl4VE=; b=X+LImFbCXe5A6EDIaMu5zYQ1ps sggfsLz9wK+Mniobm6FozUKMpip5Nsx6xA7wnfpBvpYEoPyB3b4GdeGtr94mjNAgQ1kI2LgmLuxTK 3SGlAEp6LvciVJ0A5HDCaNTuuNivJZX4u2M5ChE2lrg2GJ8FVno26rmENFsw5fkihYuZ11BMZhR7+ cxUL+UlMiEuJYPkA7wSQW/6CXbQ3cSThMrzz6OlLMqswNvI5cOz2s5bZHBYbMsD/Q6CO/7NAJic7a d0rHtxvji3KKa+wRbUaobrPyGJjtgEN41Sofcg1+tNHCH3xY6euU9mmqgA1XRZpPwd+tb2U3sg8Zp qUxmNosw==; 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 1fhs8m-00018b-Lf; Tue, 24 Jul 2018 07:53:52 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhs8E-0000PI-CJ for linux-arm-kernel@bombadil.infradead.org; Tue, 24 Jul 2018 07:53:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KpsdpYdK4Ysd+TV+/RS+nNDg3tlVVRvIVtSFn8+W9VY=; b=zWvRVdorVR4X0fChXaoXVwDBY cI6VX0c24vjL6dGzZw7JDoS0AbtZbbLmsrUYli6X9N4bSBvxna8Rz16pguF3FY8kgrQoI/YK9Sww4 mfsYP+Hw9MCoJ69D05dKhs/Y3sK9l9WIoGSXHPol2IeSV8VYhuxsRtt6mp1RgpCyMsrYWjIQd5aaZ Ngvr2zDEx1qk57dkO86Zzna3qF7U2H/nfiGxToRZN4Eb/pL0T5JpPMhQa2m1tNNeM7IFSLxONjFWl lcZb3+MnN8MovDGWSLt7yQ/fFuKmAC8Dc9dN3BkIeZj/UAFG29cGmVAdOSZOF1wi76Fx5dEvkYFBC 6lfWDkRGA==; Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrHA-0005dM-C1 for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:58:29 +0000 Received: by mail-pg1-x543.google.com with SMTP id y4-v6so2180945pgp.9 for ; Mon, 23 Jul 2018 23:58: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; bh=KpsdpYdK4Ysd+TV+/RS+nNDg3tlVVRvIVtSFn8+W9VY=; b=C0Z5IsxhlehoOj3yXB1+CXNGBevv2cwHj7x6AgVewoFkRY3kQ0tSRABz0nl9YCj1A7 dbVu0OsP4aLNOXDh73SV6cSH77OT6r6hfArvF0igrHylRoHNskMCSZJexXxcwKkK5zAa kiZ1NzeNxhvYrXTjlM3PLcerbGCrlh2W7MtMw= 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; bh=KpsdpYdK4Ysd+TV+/RS+nNDg3tlVVRvIVtSFn8+W9VY=; b=NSGHhE1rkCY0sLI01vBB9r3W4YIAlKd30RB/Xn4L64RQTrjQU72f3mDqoAqMw/Xgu3 4e43kPYOqhVvAQIjNDeRJvHBnDc2NmBu66E/car0ti8sdO/J8ygRCiKva8phBHcmxn1l OEUWZdtrZdScHWkaKr5lzMG6ZWmecfRQT73I6XlHu2oY/hWIipm/s/55aqWKcU8vlf/W WbPzU2d+Tt/8Ntt60blz6Uo2b5kkpI/NvjcOMqPjERvcg5ZbJPzkulNNY9FlQ1ZCOLSD n/KQ10SQF9vgjRnzDN07p9zS9Cwvbxj1EyTE31fdN3DoEb9pPjP2juENogmBCEWKG8J/ Mdbw== X-Gm-Message-State: AOUpUlF4BtXwBAx8PwoEW83r5T9fy1ve6y8GLY9ZGoP782U6W7KFMgYN LP+vGf84fPtkK6K36wZMz66fmA== X-Google-Smtp-Source: AAOMgpcULG9DUtF4Qj8tlxJwCcwKkpHAlGxDMh0oI9A/casaKsk54s8umNVVMPZ/tQO+WOGeKQZ2Lw== X-Received: by 2002:a62:aa02:: with SMTP id e2-v6mr16287521pff.211.1532415506173; Mon, 23 Jul 2018 23:58:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u1-v6sm21299425pgk.25.2018.07.23.23.58.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58: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 v12 09/16] arm64: enable KEXEC_FILE config Date: Tue, 24 Jul 2018 15:57:52 +0900 Message-Id: <20180724065759.19186-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180724_025828_489171_6B3EDD31 X-CRM114-Status: GOOD ( 17.84 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 42c090cf0292..a9a3a5583c8b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -835,6 +835,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 0025f8691046..06281e1ad7ed 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -48,8 +48,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 Tue Jul 24 06:57:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541497 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 7312114E2 for ; Tue, 24 Jul 2018 07:53:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6254D28773 for ; Tue, 24 Jul 2018 07:53:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5543A28777; Tue, 24 Jul 2018 07:53:41 +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 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 2B9FE28773 for ; Tue, 24 Jul 2018 07:53: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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=WeOugFzigmxGq58N7ndkSr2BOhd1rzkmUQc2amySFxU=; b=FMWWGImXL1mLvw212+OlA9KtL8 4P1tKa7wuHQags4C2CKExsHsjbcs58e8VxiKupCXpphurgIuybvFM4MtTI6NU/IaJ+08neDpGSS0X 7XAYEJnfLVlJDdL42moNPPor8foV9UIMulZGk4E0ddUrDQPIRywFveLCZq7oVESUOOJ/34iwOfrpt 7KUpcM+NkKWTlV31LG0etPBGWSMzCJ/AalkMivaXFs3Ge9I6axAhzKDHcHglVv45uyk2zFev/+8u2 2EQJNsMMe/cooTLxxgqSpz6L1NshDe/lmxlZwrc0v7hFCujJCJg44QpxGBf0lEUqNr0bkngNJlHdB Or/rd78w==; 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 1fhs8U-0000ls-5i; Tue, 24 Jul 2018 07:53:34 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhs89-0000PI-JD for linux-arm-kernel@bombadil.infradead.org; Tue, 24 Jul 2018 07:53:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Mz81qDhWmAiSNYpZZsOHlS2lDMScwrCRyCwmff186zc=; b=W8XqarNbaS/GHuew7gEy5dMFm 1ts8Aeys+EWwwVbV3GpNZZ6p4PYNMuk2okH/mppTKeTaOXAN4kZfARH7UnPlTG1JoLfgyGL8ZHpae iRqNxgtOOcaMiPgw8Q8nHuwbq+LSF01QpKbRE4OYkFEWVFvY8eIPYau0D45o6VfqrbdkjMX4tNCay binp8KmuUVGPXvvkSEjTUWwacsmYGNr6bswgrjFH16idjzRUncAt3iASbB3izZR4JQ7o+NN6St05p OGcupWtn/oh1FQefbeWK+bZ/685b7vdFxtjpKPawp8dRx6gAC3x73lBWWDoMCvFGem1TlWUGVK+zu zEou2jDEA==; Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrHS-0005fG-BN for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:58:47 +0000 Received: by mail-pl0-x241.google.com with SMTP id o7-v6so1326445plk.10 for ; Mon, 23 Jul 2018 23:58:35 -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; bh=Mz81qDhWmAiSNYpZZsOHlS2lDMScwrCRyCwmff186zc=; b=RQ5UcAXcbSjT7kEJqmhN965LpvOYV0Z3cRcGDGFFYVgWqyJibRLBHN7P/dzcX8Lig8 H6hdnIASudmJfZSMpKKwT7IMQfPIIZKbiQXoPMPBaJbnMIB/Q7+L5wJHC+4dNRP9hiOT 5KdDsi1ozfgrdztYwNUOZhOBlVcoBZcLDA/cA= 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; bh=Mz81qDhWmAiSNYpZZsOHlS2lDMScwrCRyCwmff186zc=; b=CqZL/zNtHj959yXWjJr3CSWojTvemJnqZ3upHlWKvWNLgFfMIw/HuNfqnRcP3nDuU9 +zOgMJoMW2SFio9hXinsTWrwdo6Lotco+jd2xacqt7g2fe2rTI0a1wZzkx0OOf30dZjM 96dRIdRYEoGdwtPGYt2z0+s7XLxWBZiggxe4BUmlyt9XYccxwdx9URErutcR5lQ9x6K5 /CFTgsIQBxMZn65dJLdedoff8hDRdF1BeaJGdI3sxekE6Jc2CWfLHHujggkV0g7TQVix 5bXW7/3R4Hj+gS5UC0O4Zl3KvpNUmvYFih7nrwMJVtzDlUjF0cMNYxiWTY/YGrgvgzL6 xpVQ== X-Gm-Message-State: AOUpUlHeRAWZNfVleiQzjFHn0DvrEt3EUJDqk00bLF8mr/Pr+kYHjfrl jmHQUg7w69tqpBwbw8C2ejD3gA== X-Google-Smtp-Source: AAOMgpeY6qMjDeti+aFQMQ0Lelief7UBB0CwC1tde/LJjK9Snmwgsw9zjfZlsFRSSWVFSbdvVPvrrg== X-Received: by 2002:a17:902:7482:: with SMTP id h2-v6mr16071369pll.185.1532415513949; Mon, 23 Jul 2018 23:58:33 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 75-v6sm18663643pfr.115.2018.07.23.23.58.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:33 -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 v12 10/16] arm64: kexec_file: load initrd and device-tree Date: Tue, 24 Jul 2018 15:57:53 +0900 Message-Id: <20180724065759.19186-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180724_025846_418683_C22D30DD X-CRM114-Status: GOOD ( 22.69 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 | 182 +++++++++++++++++++++++++ 2 files changed, 199 insertions(+) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..026f7e408f0c 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_buf; + 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..b28fbb0659c9 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,194 @@ * 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 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("linux,initrd-start", sizeof(u64)); + buf_size += fdt_prop_len("linux,initrd-end", sizeof(u64)); + } + + if (cmdline) + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len("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, "bootargs", cmdline); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, "bootargs"); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(buf, nodeoffset, "linux,initrd-start", + initrd_load_addr); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_setprop_u64(buf, nodeoffset, "linux,initrd-end", + initrd_load_addr + initrd_len); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, "linux,initrd-start"); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_delprop(buf, nodeoffset, "linux,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 Tue Jul 24 06:57:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541357 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 A6F5B14BC for ; Tue, 24 Jul 2018 06:59:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93F082873D for ; Tue, 24 Jul 2018 06:59:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87C8028740; Tue, 24 Jul 2018 06:59:35 +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 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 EF09B2873D for ; Tue, 24 Jul 2018 06:59:34 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=ma6E5qd3HgMWiL02D0/FUm4HnBAeb9An4EUGn8puZZg=; b=Jh5hPC9q/ffBXl9e1De+igahQ0 wUTDofxEcOnCrPGY79fv6sH99VxmnsUowwjpq4BP+3jEcZ5vmo3MJBEwGDa4b3yiWNom1H8YZxH9n Tc5qCNWgkELFRGE2ppyaahG/HWoFN2CXOX5Nm0YT/A9ChSCZFsQq56koPWBAAPWjj4XhB349+YUSE j1OrxIMAEl4UMMHvxVrEt/bMlAJ45vSrfNKoWZbkEx9jWIphAhkNIDz6/CKf82md5ToFct4OWD59N qhKrQ0OmIGElIOf0NiIeYFWaGnZ5zle/quSPEAqH55hYVqrak2JOb+eu4bnrWsn3/6dpffrdVcWN7 l7jeqslQ==; 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 1fhrI9-000331-Sk; Tue, 24 Jul 2018 06:59:29 +0000 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrHY-0002QU-3s for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:59:04 +0000 Received: by mail-pl0-x241.google.com with SMTP id o7-v6so1326590plk.10 for ; Mon, 23 Jul 2018 23:58:42 -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; bh=5WKpaAKKCjtuCon1SB1pm/aYftkpZ2mbIZYdxG7foEs=; b=AarIjMD+eO12HJwfMB/qHMlGWfVPWzcpkxlxb2HBpAVHrlxOUUXllc7QA7gWklBJtN cdRKIPzT6tYu7cmDWbO/UFfroONpilzEZSBKwURUO9bytSNtwmB9zblcQHbkSRdHh0CZ v707AQUEDS5vsdB2Y1RhxfCF37iaA1JNXCYlo= 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; bh=5WKpaAKKCjtuCon1SB1pm/aYftkpZ2mbIZYdxG7foEs=; b=YClNBWwewlOqBzQezpzwui2iyDSoaNKHSeiEG51+KrxJ5kRTENtUkDTLlxSiAqjYcH tiN8rsW0Hf23iqHmTv8BEjkVDASNy0j9b2jQUZ/TicPY8caN4+lkKnWSacqkA8SMg9tR jCR3WSDjiUNGyseMnVSFOGg/9tyVpDbj0jovzWo2r6ah4ZjT7AlArQCxyvZYbe4LLO0a 20bbcZOCoh0xy1QEym/Omx3kVoWj5vyLic1zq93iW8kA3MZ0OfPhZJyi+mGbotBgPZn+ JRgVeNze8vtmP/EKIJJXuzRoSC7+d8JsGXlMZfgMQsPxwg40WdhHCqk8ATiFo1ryfzAg iv7Q== X-Gm-Message-State: AOUpUlE7piJOh+amEf8C6Nu6kzRPc7rVvm+faueLWP+w14Tx8R7NVn+w wa0K1SHMMv44OErHeTcezzLZ0Q== X-Google-Smtp-Source: AAOMgpdIjXVDwKvwEx6LpQSSVbHsEkYtl7LnJhyJ7/I4Gdql12SK1UEDVdt1Qy7bim94laOmKDpjQQ== X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr15545045pln.197.1532415521548; Mon, 23 Jul 2018 23:58:41 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s16-v6sm14600661pfm.114.2018.07.23.23.58.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:40 -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 v12 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Tue, 24 Jul 2018 15:57:54 +0900 Message-Id: <20180724065759.19186-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235852_330142_F3D3BD86 X-CRM114-Status: GOOD ( 18.92 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 026f7e408f0c..5d102a1054b3 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 06281e1ad7ed..a9cc7752f276 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -50,7 +50,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 b28fbb0659c9..b8297f10e2ef 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -20,6 +20,7 @@ #include const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Tue Jul 24 06:57:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541359 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 BE874184F for ; Tue, 24 Jul 2018 06:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB25A2873D for ; Tue, 24 Jul 2018 06:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E8DA28740; Tue, 24 Jul 2018 06:59:50 +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 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 17EFC2873D for ; Tue, 24 Jul 2018 06:59:50 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=n4Xs3Nh5FgUeucwOaJPq9nTXn5DPt7v9vAHqpOgapfw=; b=Jync8mWllk6GqWqlQwvR8gK2OU YrTm+hs+WmWKIk7QpWpnGSJgjmiQr5xPd2Ur9rEruP9dRXcDlnY3PV2s50LjOHTIxisTDHS/V6p9i qpmQQ8m/5fe/oywGbkupD6IUjDAhIj82sHWpBdXofMVsZBAyVwruNzaD1M73PbbZeZoj83fyiFO87 XAdpHkYmdjGExhEa2SZtmGuQMeEn2ISmwvuiGaK5PFQdiwTMPtJT3J+kfvgdAhF4Zq8O979ah3g4V CulIi3Pkup+Qhg95BpetXXYMnec2qhWT119PANad14GXugZqX/k5uwIuql+c8UKUouGS4kcrwVDH1 X6Aj/jdw==; 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 1fhrIQ-0003Ob-3V; Tue, 24 Jul 2018 06:59:46 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrHf-0002V2-J4 for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:59:11 +0000 Received: by mail-pf1-x443.google.com with SMTP id a26-v6so624206pfo.4 for ; Mon, 23 Jul 2018 23:58:49 -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; bh=NrZw1260Snx5buwrLrr5fcvVbV6cTmqraLcLZQTZkLs=; b=Y+n40Cn0PUxEfrHIT/fGbjCmcUHa0Xn47ymffC+V87QKT+cNafSRa5tfjMDNQ2XTmU gA/8rCZYwmQc5ZETtw1o6TE3N59f1pjEOgIPXXNAN0FE3ykbdYs/aEOUcV8sYm1lLANC ATiFdhuXXARVZGjQwDm63+lpg0G1s6N5FFYks= 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; bh=NrZw1260Snx5buwrLrr5fcvVbV6cTmqraLcLZQTZkLs=; b=QoTLE7UxjpfrlxWyaQr9INqxgzBi2+YJ97VzMQjVsMBIiScQnoY8b5G6iCExLP385q jd/Hv3hdQ/4bwfWOb1P7XaetrLR/oCOxhhLfbnbvrF1TsgjWlGyW8JfZEyXeHZlfwS9M 7/+gTOe2mpywAVcxvW5KySpOynQcx+/keAIRdx1QIVaZYdjG+8OhknEWeAu/BZ5x4Gwq K9XLOPtl1guhGpQ5/9ZS6rVnOOux+32O6daOIiJ6l3f96zKTicvgx68b8+I0NSazaE43 FLKI79+o8rQ4vJNFC++CqRx37YqU9MYyVhNvmmi9MA+urYtjN79k63Sg95IFE2nMSrmX aNDw== X-Gm-Message-State: AOUpUlGFraSP8mKqAi3lU54fUls2/QRRmJh0KgrdjUpAIxSh4XS+soj6 Hu9mUBYllD4VCporMcMry/S6fA== X-Google-Smtp-Source: AAOMgpe2E+msjm/gLvLjKZTckbG8bUtjug8td3OJN5Ihk/T1HjIzOuhOvGIdcXO/RXtSkHaic/LZxA== X-Received: by 2002:a62:6746:: with SMTP id b67-v6mr16504274pfc.243.1532415529050; Mon, 23 Jul 2018 23:58:49 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 87-v6sm22962394pfn.103.2018.07.23.23.58.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:48 -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 v12 12/16] arm64: kexec_file: add crash dump support Date: Tue, 24 Jul 2018 15:57:55 +0900 Message-Id: <20180724065759.19186-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235900_087357_E22333E3 X-CRM114-Status: GOOD ( 21.06 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 --- arch/arm64/include/asm/kexec.h | 6 +- arch/arm64/kernel/machine_kexec_file.c | 113 ++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 5d102a1054b3..1b2c27026ae0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -97,8 +97,12 @@ static inline void crash_post_resume(void) {} #define ARCH_HAS_KIMAGE_ARCH struct kimage_arch { - void *dtb_buf; + 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 b8297f10e2ef..7356da5a53d5 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include const struct kexec_file_ops * const kexec_file_loaders[] = { @@ -29,6 +31,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); } @@ -38,12 +44,30 @@ static int setup_dtb(struct kimage *image, void **dtb_buf, unsigned long *dtb_buf_len) { void *buf = NULL; - size_t buf_size; + size_t buf_size, range_size; int nodeoffset; int ret; + /* check ranges against root's #address-cells and #size-cells */ + if (image->type == KEXEC_TYPE_CRASH && + (!of_fdt_cells_size_fitted(image->arch.elf_headers_mem, + image->arch.elf_headers_sz) || + !of_fdt_cells_size_fitted(crashk_res.start, + crashk_res.end - crashk_res.start + 1))) { + pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n"); + ret = -EINVAL; + goto out_err; + } + /* duplicate dt blob */ buf_size = fdt_totalsize(initial_boot_params); + range_size = of_fdt_reg_cells_size(); + + if (image->type == KEXEC_TYPE_CRASH) { + buf_size += fdt_prop_len("linux,elfcorehdr", range_size); + buf_size += fdt_prop_len("linux,usable-memory-range", + range_size); + } if (initrd_load_addr) { /* can be redundant, but trimmed at the end */ @@ -73,6 +97,23 @@ 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, "linux,elfcorehdr", + 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, + "linux,usable-memory-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, "bootargs", cmdline); @@ -129,6 +170,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, 0, + &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, @@ -136,14 +214,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 Tue Jul 24 06:57:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541493 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 DCDDE90E3 for ; Tue, 24 Jul 2018 07:53:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D03AD28773 for ; Tue, 24 Jul 2018 07:53:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3FC22877B; Tue, 24 Jul 2018 07:53:19 +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 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 57FC528773 for ; Tue, 24 Jul 2018 07:53:19 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=Jm9RRSb/yuOxP16pxewToUDfwXoiu2qeVG1CjQTK0XM=; b=mo8ANuebZogA3b7zB6+rCjBkkb m+YTxR5VEeYKAGuxRHq7BsJ1UeMEkqi3oZbO+EhB/3e1raWlOouibfG2RM3eUhXAOTTyjGVmOYXwB 6zFvWdtSz/YBu1/g6zsN2h8cgU7uAG4jMR67yQxYiCmXVVVzfEQKOPqKB/BKhvuuMmk8wSDorBkyU AmkdMrOUuMckWy8v6Sl+s5BV5K+GbGaxlohL7vOXIgvFvojTJ71mX5fWDwhwfb6OA70afmmdRQYIM 3kE3ftakfsQReTxHdg/rA5LZgY547LVCFc2sa2iVSoJtzVYy1EPdzYjq9MtDQZ8vwa9P6KM9i4YXT 0X2TAhBQ==; 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 1fhs8A-0000RN-Hy; Tue, 24 Jul 2018 07:53:14 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhs87-0000PI-SI for linux-arm-kernel@bombadil.infradead.org; Tue, 24 Jul 2018 07:53:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LYcgh+nDPKM588JQ9ma6JrqSapqsGrXqoeVmNFniv60=; b=GbAJEb9lOL4/CxgHWnHQfOasm X/FAT9fXArAq67YWq+EUwGKoC2AJ2Kkfvza7q35oZm2sEA3vgYhNvfL9caRDWGRUwnep6Jy1U4Ei7 BGtv0x0hlV1tp15NuZrKfgvYdbecsPkoaiKfr40g3ugoL5PUyrQIm6JTRLXU3eVUEwrr0myvLqozT GOtHXcS7vaUIsG83TZ4TuEbPdNEYlaHHSRP27hpeZD0yNp7t7Ix8k87sn6aYSl8S2yhZjdfZkjkko SzUDh65rSkk0u+e2K4gK03ipq1PYwQ6e7n4U0DxPUFXzPYuXW/gRC/k6Vs+WVAzLqJLhGJYxxAeMa UpRfBR/Eg==; Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrHp-0005gv-8a for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:59:09 +0000 Received: by mail-pg1-x543.google.com with SMTP id p23-v6so2177056pgv.13 for ; Mon, 23 Jul 2018 23:58: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; bh=LYcgh+nDPKM588JQ9ma6JrqSapqsGrXqoeVmNFniv60=; b=Tj1Kn5X7glWk0eA5Au7pf8DoGG35+0gnsScbyK63dcH0svlRAOtYPEmMQuiuHFyfvn qfhUyZPYaVraqD4EiL/GszUO461fcspkMlOuT125/tkekt551LIlH3/DhV9mJlo+nWtf IkBO56LtgEpsDzquzEqZqia1bu3RYc9Ef7Jl8= 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; bh=LYcgh+nDPKM588JQ9ma6JrqSapqsGrXqoeVmNFniv60=; b=iC7HlNthLNoLd7cA2zWm8J4QDZxRqHy91pdDPp7I/vFjM7SRM8k1o3/6sT3/6rCMAv yj0FikHtRv8RbQNWaBBjuKaSEUVoQ0XJVNQcy+AAmA/9mP0zfSLIsNqshkaWKcJv3ato 925sOO68Hj/zOQ/c/XBJjSSHats/st+dQUsF32Swwi1nR8iLjGmFV+H1v8/q62D2oJzZ WdiOEZjmWxJlcQJLrVZrLX0khTkaAUG7xUF2pJgVjj2/0L5TaSTQl/YpiNi58FfAZXc9 2OqChqpt1JX/ZVIyxsmG9qKTnGFhlwva7aDrWpY8htq8kYLM+EC0vnCcAuj0PAc0eyiK qsuQ== X-Gm-Message-State: AOUpUlG/seuFTfe57sObToK1PjFlkxuSu8BlvBer+d5yi3BZ3EgIqP/K 8y6ijQDNC6jvEp7RzgLlZ+5unQ== X-Google-Smtp-Source: AAOMgpeL+YL92DjiK/BLD5vIT6GASjU4kc2OQmjU+/U49ayZjvZCokZNxmDfJzYiI2pyAcaAWfaJ8Q== X-Received: by 2002:a65:6143:: with SMTP id o3-v6mr15494531pgv.52.1532415536850; Mon, 23 Jul 2018 23:58:56 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x22-v6sm503821pfh.67.2018.07.23.23.58.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:56 -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 v12 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Tue, 24 Jul 2018 15:57:56 +0900 Message-Id: <20180724065759.19186-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180724_025909_317158_A5785731 X-CRM114-Status: GOOD ( 17.31 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 f76ea92dff91..830a5063e09d 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -205,10 +205,18 @@ 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(kimage != kexec_crash_image, - reboot_code_buffer_phys, kimage->head, kimage->start, 0); + 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 Tue Jul 24 06:57:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541361 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 C6A7F1805 for ; Tue, 24 Jul 2018 07:00:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4DD62874A for ; Tue, 24 Jul 2018 07:00:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B286B28793; Tue, 24 Jul 2018 07:00:09 +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 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 4A6742875C for ; Tue, 24 Jul 2018 07:00:09 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=31FO+3YWw+lbgK7CbqFVgxHXdp66iMzrGJV9CRXr2OM=; b=dUhGxe4hH/I7LhTgsKJ4+dqY9K QxDrBWxH6IStBF7FOlefZ80Dn4CNmLLLPcKZzaWRdVtDSGrX9AqNwlTE34D6ZwXcMqE/WQWPqCIou rvmQNyLwRaeSt/unZkO87KHc/UpoG5zQzWws4YsPNgCEceOJDC1BqNzdqM0iUWQSzu4yMrbhPI2j5 jIuU2fXrC2GgoC0t65WzIVCiy14t+Pb3HOVhY7KAFks3ZfhDc7mgfsdwVSctQ3ViWFhqKvoKir2TD y5lpijaooxFlCh0kIGmmEEeAmcVR5l/G9v3borse/3sH1Oa+enq000w1ebwy0x1EILSsraesaELiu pTpgUBEw==; 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 1fhrIe-0003hB-R4; Tue, 24 Jul 2018 07:00:00 +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 1fhrHu-0002mP-V2 for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:59:17 +0000 Received: by mail-pg1-x543.google.com with SMTP id g2-v6so2185507pgs.6 for ; Mon, 23 Jul 2018 23:59: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; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=YBqxVMLixn/XZ7QzSmXVIbTgC2hE90UJKhy++UyocFiKZo1r0isSuzudJ9uMFczRAk 33CyhfGgCIlK92u0bTUhQSMunExi5YOQUhEIe6Myke4ydsrIUkeUMIuKoNyPDP2YFTc5 pRfh70mIT9IfPcJhoFAMaH2RK39p+KF9d1whU= 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; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=NYFppe920sXn7RMO4uzlhEuRAYJlL5W0eywt04ydtxT6B5I3mJirwoFHvsYcxD4247 JvjEKiHcr8pWYf7N+B/JUKSnHTCTs3GddZ+V8OAPTp/MayJXiSoB4yalPn4CCGLtTZMu 0pozlBr2JWAI7dTsxxlBxIEjxjKW7tB4/s43VwpNZwSCOUHgTAvvo3yBZze733Uph7iM cop6FyiuMS/dG9+GnDh3/DNyi9qEDJAcM3fVASsF073Um541efitasKwMAWmQU4yfgq/ ncUKAJ/dZRh1hMuuXKuwz8lASIBV58cIt124KG05+CoHoJiqSd105wYlvVAI8HEr8Ptu 7REQ== X-Gm-Message-State: AOUpUlFnDwwySClLiSFKUXw2cDTG8hkvrNZmYwRfxwP/P4M8S4yBx5SS 5YeG4gZXurOF3PfgmU1en6cD2SCLUuM= X-Google-Smtp-Source: AAOMgpe159jr6QMwSXbmOfuanH41Nd5SHLHv/V/dCDQSHVNlsCxAKBEi+X3RC9vtgB8JVrA53KQuRA== X-Received: by 2002:a62:1603:: with SMTP id 3-v6mr16382476pfw.245.1532415544496; Mon, 23 Jul 2018 23:59:04 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z5-v6sm9588659pfi.4.2018.07.23.23.59.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:59: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 v12 14/16] include: pe.h: remove message[] from mz header definition Date: Tue, 24 Jul 2018 15:57:57 +0900 Message-Id: <20180724065759.19186-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235915_072205_FCCDBB64 X-CRM114-Status: GOOD ( 14.95 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 Tue Jul 24 06:57:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541363 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 59EE914BC for ; Tue, 24 Jul 2018 07:00:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46D4F28786 for ; Tue, 24 Jul 2018 07:00:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 449C12879B; Tue, 24 Jul 2018 07:00:48 +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 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 CA2D6287DE for ; Tue, 24 Jul 2018 07:00: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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=V3JRqIxUVgjor13lMFQBfjueB6yyPD2ZmLVh6ycW/L0=; b=WYk9qSGBMI42EkuCLJ6N+9Uzv5 bWfIITidULe0sDjmGbSWsgFh3OsbkqT69kJxkLkpRjoMhr3Qxxoz+ACQJyjkTi8dQbPoMM8eSP02P y0jxz/md+C4bxqPcgFtUoaZi+wZiZS56vGbg3xDChrkONYNdIokW9npCYT6HmsuQVlZ40NiO9UPaP Cplr/nFgjPqkMikqwuwRETvzNWat68QgFPhjsu/2hngLtvyOIUF1d2hjBKvgWjW2pqkoDRIun1l0G Lq8JkfOSRtn7waUpPSxboT2qfWwRAxfitZUINS3GYxCHJzPbXKYw3pQVxTRsalOUnBesnMz4irFLb OXEv17ww==; 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 1fhrJL-00050R-Fa; Tue, 24 Jul 2018 07:00:43 +0000 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fhrI2-0002qQ-VE for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:59:34 +0000 Received: by mail-pl0-x244.google.com with SMTP id 31-v6so1328620plc.4 for ; Mon, 23 Jul 2018 23:59:12 -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; bh=pwXt6vap8yHX0ws+sEoumnHhs6bkGBBWSifGoV32A7Y=; b=YqMA37RPrwDG7QMbekhUUHSkhSv6lFzDpMZn38BDZBonF4qxQNMpXVgwHX0+Qg4Oaf /3V2lz1+76QcGqE/OOehIRcxSCjbF29D+xDyrTkr7sDoabpzDYPx0ChmHhvLY1fX1Ugx nZr0y9zbP9jAzyB+admjVWsewji7m/SKzXCro= 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; bh=pwXt6vap8yHX0ws+sEoumnHhs6bkGBBWSifGoV32A7Y=; b=a3p72zzgw7C7QrtOg/A0oJIcsq8Ur58mlYgAiuBwArfGS/EgwKfaqdpB0H1kv7EN/h HY2XO/fGECHkExQhSqHkVTXvek+OCxI9O7zFFOXtxy62ER4pIRoBE3s+T7U7Kn4zTu6i KGebIcWtCablsIDpEPTgHxb46Xp13Su1c1u72Wk3ekN7CLWryndnxfqlm+nyBj7UvOYY 0UDEoMuDppUipaQQ2kocn7+cBPM2HIiJWauQhnFUxRgrnu8z040GkHaJ5LF8Nlob6rKU R6SzSa41kVVUFoQUF1r8BvvlsLAt95OCHagEDJLo0ZISk6j+qcweJmnDCdm8py1Nj+rH xjsw== X-Gm-Message-State: AOUpUlGoYkfJBDcpDa5GbuBINC/10Zed/CDeP0Lmmh4mcaTVof3/O+d3 gipEt9tUHY+rjxcmcnr4IGaJDQ== X-Google-Smtp-Source: AAOMgpcb7hEP3pLLw18pY8MBctvEOFfhWftNlRycrBUzZ0Kk4b1IfHhUXCb9BVsnasaF7rHcXQUNog== X-Received: by 2002:a17:902:8486:: with SMTP id c6-v6mr15657253plo.283.1532415552316; Mon, 23 Jul 2018 23:59:12 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 21-v6sm21506976pgx.20.2018.07.23.23.59.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:59:11 -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 v12 15/16] arm64: kexec_file: add kernel signature verification support Date: Tue, 24 Jul 2018 15:57:58 +0900 Message-Id: <20180724065759.19186-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235923_371281_9A3D2608 X-CRM114-Status: GOOD ( 16.27 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 a9a3a5583c8b..1445eb2fc833 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -844,6 +844,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 Tue Jul 24 06:57:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10541365 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 74A3014BC for ; Tue, 24 Jul 2018 07:00:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C6DE287D1 for ; Tue, 24 Jul 2018 07:00:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50535286D9; Tue, 24 Jul 2018 07:00:58 +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 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 E0F242879B for ; Tue, 24 Jul 2018 07:00:57 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=hs8hsl7Xzfvxd7sxM3i3GEsCePRLjOu8uBeYi7geVw8=; b=lFsO9pBOxpxXRFIObNijqphZVf 05KswWoGmn08CBGY+NdpDRF8CXJHb0xdPORjsSS0/wsHaJsHZwh7h6QnOB22WGtq60I3wON0lEXAN Ciu9fYaQdLF3jQbsuvacxK3cMGQtTmfSAq1NroVJff50qImomALQQwASen+a4gQE4GI3La2GzTX9U z1NnoPsPK0Fp6uHP9UPUL11RmH07a9QV+3aQiYLLcOfFLt5G0Y7rA6EdeXpWL3NXELfgyS84rKfRB goT5CA7/qSU6NeN7pfHIorb7NWm2V+esqSpD35A0CN7XoM73mq/BfU2likoA/aD5ZTb2BXOsuvWRg JnLt0idQ==; 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 1fhrJV-0005HC-GV; Tue, 24 Jul 2018 07:00:53 +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 1fhrIB-0002t3-7l for linux-arm-kernel@lists.infradead.org; Tue, 24 Jul 2018 06:59:41 +0000 Received: by mail-pg1-x543.google.com with SMTP id n7-v6so2192897pgq.4 for ; Mon, 23 Jul 2018 23:59:21 -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; bh=DjZGq5WnpjvJN9iGuoJut9k6LjLfxTrv7tJcxElB2q4=; b=LOBGvQ46EyOi/qHw58fwmvardQ5MtYZdZsKI2bhd3NPyZ5Ngm05h1zVfpxB28HzYsy cC4OHjfFrWjqeyA6R50p272ExOYbm2fuM7josvLnYlfJCXoyHAdXS4h6od0vIP6qBJNY +HYqMAUASv9ZTXy+It/cFonObSZhmrKAg+Pqo= 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; bh=DjZGq5WnpjvJN9iGuoJut9k6LjLfxTrv7tJcxElB2q4=; b=XoSCuM14aO3dEeH0apQ4Sb3su5QzK3TxxK31mva9nK/08fuUWZ6ZRS6HOuaa8L8gwB 0n3jey7JqogNbbrbmxm8k93lYnH93Zmq2QkhHgTkuOFynZ6IXhwumz0CdXbQzPePA2kl tuHyvu9Hfqib4+L7OwDtJXEk8hz0adjjumzxJT86RLir9A4FeGNphs3ACUl3YWQfE+0h Xe+gex0edvYsjLayMVJj7uUn7zlL0jPu1efK5ghJiFh0KnW4q4sbQRaklUv4NWlqlod1 n57c7DtASKTj1KI8CLJJxLqh4nrQ+d0AEgk8XZzFLOqnvOZmRmkP6JHSx4fMv5Fg6urc EU7Q== X-Gm-Message-State: AOUpUlH6hC2coFO0ap8tkAtF2Gw55eAzy74+s6szPuTE6KgVZcVQfp8b QQ03FfBkCZHFakIatpoyQ3sVEA== X-Google-Smtp-Source: AAOMgpeZJQX0AFXWrZnMLMf6ZKT19Qyca3w2nyk84CUXSpX7nVw5iYBL8EJwUB53Ymd+ne0tHPLXTA== X-Received: by 2002:a63:db05:: with SMTP id e5-v6mr15062646pgg.152.1532415560822; Mon, 23 Jul 2018 23:59:20 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c6-v6sm2027520pfg.138.2018.07.23.23.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:59:20 -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 v12 16/16] arm64: kexec_file: add kaslr support Date: Tue, 24 Jul 2018 15:57:59 +0900 Message-Id: <20180724065759.19186-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180723_235931_857011_2F6C7EFB X-CRM114-Status: GOOD ( 13.92 ) 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, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7356da5a53d5..47a4fbd0dc34 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 @@ -46,6 +47,7 @@ static int setup_dtb(struct kimage *image, void *buf = NULL; size_t buf_size, range_size; int nodeoffset; + u64 value; int ret; /* check ranges against root's #address-cells and #size-cells */ @@ -158,6 +160,12 @@ static int setup_dtb(struct kimage *image, } } + /* add kaslr-seed */ + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop(buf, nodeoffset, "kaslr-seed", &value, sizeof(value)); + if (ret) + goto out_err; + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;