From patchwork Wed Aug 1 07:58:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551795 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 8E11214E2 for ; Wed, 1 Aug 2018 07:59:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EB2C2ACD0 for ; Wed, 1 Aug 2018 07:59:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 721162ACD3; Wed, 1 Aug 2018 07:59:57 +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 2E4A62ACD1 for ; Wed, 1 Aug 2018 07:59: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=mu2W7qPpCIlOZTxuyT1oEmo8SCMNFykgYRZ68hFnXHA=; b=rPxIBpkCFKR5WnjpMyWN+eLebe 2URRoBASS4RzcX2U4uAeZ4wnGNQE0MIVgsiu6vQcOXz0RXeYGWVYH4FY9xWFlnRNuI3j1dLaux54Q NhrZVTGMSIJVvZix7FTE5gGy3Jxj4iuc29D56e4zrM10VzEjeSHff8f2sNI4gWoHHn6D0eSE5JltS 85oyFDhvjS8hisXzj8OiUdKbP255sgf50QNiCS9T8r0q6BL7jf4Z2Xy+U3BaJidyW+Z8ER45R+rDz 1NFdjfa56A7zmwRQt1m0sHhCxZJAoJukGCBgiHyNVOBwE/Nh8wnYca5uqGBaUWdUQnhixift8xpl/ iaht7uIg==; 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 1fkm2x-0002qy-4B; Wed, 01 Aug 2018 07:59:51 +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 1fkm2n-0002Xo-Tl for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 07:59:44 +0000 Received: by mail-pl0-x244.google.com with SMTP id d5-v6so2870086pll.4 for ; Wed, 01 Aug 2018 00:59:31 -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=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=CJMXHZuF272lx6p1FY4vncZVgCLe5vB5pCCZOhKzIKR+dFmQ2r/BxKJRfYB5oeQUzz VfrsvDDunR3HDwVvUEILpaMpzgfFeDVqwu77PXdIdQY4qWW3tbsFqyEKw3rpPSiUKb9N Tkh+9w1KLuhKxTJCChfXdSjEJ38fv0SFB19+I= 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=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=lWPN5/wkeLkfW2K3xkclJWLthGpHp34+YJiDkm7qjKy5Y0y6ZdGGZZuDMVSGOWx7/H ElNaBrW+Sim8+fJT2l8o7Qjb5OmrzxzDmL4EYXpQ6XtrT84g3Cv34sNdgI68qUM0orKu UsJ03qcOuUjMY1Hs29oVJYzz+Chtloprbp8JzPwtS6vWQbnIVad3SL67DN10YLdIyT6o dBkeWXL5mFGpB72qDVI85qk8lF+SIOnmK0nYmR31qjho2o630JjkYaSz2c+bq0XXsCGe HWa50IGT07haf9Vh7iXAuEE5BTJSOk4O+Aoa/Ojj9U64gnTlfAMi5C/9rDMeuQq5YFcD intQ== X-Gm-Message-State: AOUpUlFjSo5kZg/TcZ0n27h5s+7j6JlXu6LwpUElodDt8ZTDAJH2/+1d Hts5Uci/M/tw1+VJQRVkr0Xelw== X-Google-Smtp-Source: AAOMgpe4dG4Mhg85GoOTnrcvSX+CAMg7n12TVTHFvRU1htzsZHK6fyHUfc3Rxd0Lbj/UG1OjjZFSJA== X-Received: by 2002:a17:902:b785:: with SMTP id e5-v6mr23561403pls.339.1533110371491; Wed, 01 Aug 2018 00:59:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r81-v6sm28580218pfa.18.2018.08.01.00.59.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 00:59:30 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v13 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Wed, 1 Aug 2018 16:58:05 +0900 Message-Id: <20180801075820.3753-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_005942_351690_A1484E83 X-CRM114-Status: GOOD ( 11.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 df4bedb9b01c..acea91e49523 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -736,9 +736,11 @@ __SYSCALL(__NR_statx, sys_statx) __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) #define __NR_rseq 293 __SYSCALL(__NR_rseq, sys_rseq) +#define __NR_kexec_file_load 294 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 294 +#define __NR_syscalls 295 /* * 32 bit systems traditionally used different From patchwork Wed Aug 1 07:58:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551797 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 5B286157D for ; Wed, 1 Aug 2018 08:00:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D9572AD03 for ; Wed, 1 Aug 2018 08:00:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BB4D2AE4D; Wed, 1 Aug 2018 08:00:17 +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 E10F42AFA4 for ; Wed, 1 Aug 2018 08:00:16 +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=dftFNxRqaVShrmt4MY/aPMIdgM /KEh9Cg4szv6kkupBIH7c7U/9i1BCzp1xe1QlUETnm8S5CW4qjCLehJhuEST6sokJdjVeNH0A1nmS EYVM21FLwaSGhRP5K5AGUEDswDkrPhyiw7ICR5XQP09cAUIl4HQW+EHTG+YNm0bgYbEdt3BtC9Zo8 yQx5/qVop42NkBpdnOHM8/2JYpTwtHgIRZZugbmPGyrabp8npn6PVgJdm8/1kWL4/XBs066bKm6BZ oihgNNPReEuKD6tsB5ImI/lou1I8YqNOUDfqg0iQHVWqP3GmebgYx8+qHmdqaX7pXMK+vYWcD5HpJ XuZsO/7g==; 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 1fkm3H-0003M8-Eo; Wed, 01 Aug 2018 08:00:11 +0000 Received: from mail-pl0-x22a.google.com ([2607:f8b0:400e:c01::22a]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm2y-0002ex-1b for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 07:59:54 +0000 Received: by mail-pl0-x22a.google.com with SMTP id d5-v6so2870240pll.4 for ; Wed, 01 Aug 2018 00:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=Uv6f8cOuilyrUsJMwLSlGkRsQmaIQ1ADH2CRLyaqS1MpDoCDg9EIg/Yyi8CKwZN531 Pg27JoHeDbf/rAIG+ng9/UAhO78LOa0MbUIO9GrNUNlODrSUcS5Q48gdezcN/n5aBrfv +/r0CXt9deoc5LYcWq5DhwNbdofl3xb/8IY+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=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=PLfNU8scvq/iJ28JLtYv+YJ5XxkD/9OGZ/xc2XF38HV+L9ikj01+xTbeg5yHNKx+gm UnGBR8V736zCwREhmr5UvN8KJjskZ6VvYCUGqO2o2a/9Wfrb1mkg/nluQbMSSXLhC3uN TC7sFOELJoAYGXPt6iqS/s5KWb3RQK05za48Rtb3nYtuwgpEptWL5FtqtcvlXJoUALRy 3EoO65IEv3svfORqAQmVcfHkZM29c4m1F4hOy9s1+SVHfak4UScmicWLKTdpTREfVQM7 JHR1uaGwtW5cYSOkaMDU7c4HNOqwM7t9503xcO7crwbSYlXYrqFxcbTyIvW0Jj3yz2uC St/A== X-Gm-Message-State: AOUpUlGGSTNvZX8Q+pFeT2swW8ZfJur5p9IakuSa5R7FPfTZ7/38m873 5XmwKhdFBEZ8dRKqZh3/5zBHRg== X-Google-Smtp-Source: AAOMgpdCoqC3WH5zP0l3/qAhWJAeT4udXTWZ1D4XtyoLYSRRcAjuK0Li0jr7sPr18Th8I29AYe3RUg== X-Received: by 2002:a17:902:5617:: with SMTP id h23-v6mr23475174pli.324.1533110381241; Wed, 01 Aug 2018 00:59:41 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r11-v6sm23617948pgn.62.2018.08.01.00.59.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 00:59: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 v13 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Wed, 1 Aug 2018 16:58:06 +0900 Message-Id: <20180801075820.3753-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_005952_390669_FDAA744C X-CRM114-Status: GOOD ( 12.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 Wed Aug 1 07:58:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551799 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 18928157D for ; Wed, 1 Aug 2018 08:00:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0941E2AD09 for ; Wed, 1 Aug 2018 08:00:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06AD82AF7F; Wed, 1 Aug 2018 08:00:32 +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 9B24B2AD09 for ; Wed, 1 Aug 2018 08:00:31 +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=mEtGbVoMWV1+bu9Py2rcDkJZFmkSK8u6sKgkiDga6E4=; b=VC2r5ISc3KzTdPB5PC0c1R3QIW yEW+FLvx1XiWqHQUwjiPPDrvI4F5uAS2hPAqcWlRUWcxeCAVKpJYAtOi9Fg/qWGpeSdcpa9qVzRMK MEcURo+QwnB9xF2TmxLyt4252KcnAZMY7EZ9DcsQJoidFW6COrWrA6N/kDIPioVN34HBfzf6V8qGc NwXOSH2C7UqVNbmesaU4KklU+RDt985EQe/DGBv/MP7fgKy7wA++4DNzGVCcsO+zAKlHmLGdEoexn emWl4hIkzoqUmd5Q1QEZxtkdNU/ow571dWMb3BhNNWy6VP8NyvZ8hI0z7qaaFnD8wk3zBPDmiJnYu Bhfhf9Fg==; 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 1fkm3V-0003js-2L; Wed, 01 Aug 2018 08:00:25 +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 1fkm35-0002pj-Pe for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:00:04 +0000 Received: by mail-pl0-x244.google.com with SMTP id u11-v6so2870727plq.5 for ; Wed, 01 Aug 2018 00:59: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=68DGwEYhPm491eIfZZ6KO/KX2jzukwPpQsbkiYBWDXE=; b=Opukkf/0wWc9eGzUj6XgdTjU9cGErNSQjnL4XLZtEr66NATP3fC2Nd55/otDP6Jk41 LZYQnjeYFyqlGr+gcK9uAD+nWrfUWaoyoBG42/6bIST40Q2+NTrTDWXGA5plcmH2UbSn S+FFm5HCGuPvK9E1HKml56RfSWFQfIsB8b4Ig= 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=68DGwEYhPm491eIfZZ6KO/KX2jzukwPpQsbkiYBWDXE=; b=DZ3mqWsGzLbicz2nfUQCYndylCYgFvYcYxoqTm3I0XdHm0YC/jJsRvHNLDYM7thpL/ EnhU4pWTiF5BM1w81267GiecxSqnnzrLWs2Lh/7KBvceO923xhzWskPBWW28Algjvu9p 1S7R7cB/iJL8S7r8Vp0gqWN9qCM5RJ7WQCz2B8ISKrdnUyCDQ2nHeLTiPgWXpQCoZqPc Iew1lBDAtSU+4sDL7nh7dGK9EepsMvMegHQpfRzsgWGNV9I7cGLDAmumq/sIlRtx32TQ XNZn/xbuac+EPTf+aTLso9pRbgzVRV+vdcg9AiYWyhOmag0eOJNMKBW5RsGEG9z0SRYU myNw== X-Gm-Message-State: AOUpUlELE3mS3t8w4nX9JUKN0xUbH5PlZEfVMwrMaMnNVBSqc22/tzKX qWAm3eq80yiqkIvUdb7PmuVnJw== X-Google-Smtp-Source: AAOMgpdHPnj3RppprbBSdZD1PUdyE6SMEmtZqbIlnESpFoIpLWJHfhTqjnjA48bVu0wNn9dNzzrPvw== X-Received: by 2002:a17:902:778e:: with SMTP id o14-v6mr15537568pll.198.1533110389383; Wed, 01 Aug 2018 00:59:49 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g7-v6sm21547776pfi.175.2018.08.01.00.59.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 00:59: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 v13 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Wed, 1 Aug 2018 16:58:07 +0900 Message-Id: <20180801075820.3753-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_010000_214438_70E66125 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, prudo@linux.ibm.com, 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 Reviewed-by: Philipp Rudo Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- arch/s390/kernel/machine_kexec_file.c | 10 ---------- 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 Wed Aug 1 07:58:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551831 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 7B7F7157D for ; Wed, 1 Aug 2018 08:10:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 690512AD5C for ; Wed, 1 Aug 2018 08:10:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CCDD2ADEA; Wed, 1 Aug 2018 08:10:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI 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 B49652AD5C for ; Wed, 1 Aug 2018 08:10: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=+uTTbHo1DtTBVeQM93SAlG/iK8XGmcAVfjs1m/tWIxA=; b=QO1iCYPVq0hcgoJEEQ0HNlcNZc vWQ027Kw16aHi9adF5XsIrkzIPAfsRrusniylyzHln3kNhSTTby1n5CuhBHh1mO7QPWCuObwLs8Zy SeQRi09Kpo3sHmKyhUFC7/a31ETRht/w9uiXdO1nVIyOBhvsLiHb51ikWyUdxUuxhPEjizihggk3u rdkWpa/Zg68djG0uA64yWmLbOd9rcoL+cjt7Hg7z2dNxmXy6E5m+dNto4atyn+4B9vMh+QA9i7bO3 rFDEzGPX+JOkmmok1LIWf4Nv4TY5c/bMrhUnCH26cjTnfQMAYUTqRWXAkY1BylOsuyJI9ovTi7LaY 6AZnIpzQ==; 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 1fkmCn-00022s-Jo; Wed, 01 Aug 2018 08:10:01 +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 1fkmCZ-0001Td-CX for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Aug 2018 08:09:47 +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=xe+ptcwA2jG1hIMUvqrzyq16x2eFJronfOhv7p2qODs=; b=a+M3lwzIcZXEMUwdqkir5eB6X 1oy1GnJdsVi8+rUR9sEABUBSDMLAj3zllXMJASUHvHILjnvQvdb0yqm475CGxxmEDCnnAnUdvqix9 KuzqmZydbKHoLAdE78NzvHD33MVFNdeX7st+JJo2DGMwxhgAgG4Lft9EXfhqSxhQj1e8ReYsGMXnl Uy30Lx/Pp9LVwRiFfe3HEvP6OiVz2SPu3D9vLB+5oLbJYXfjzTrE5XMPe6TzxEYR7y31r7Djg62ez 0P1a6o0SinZHrP9gEgVF9kUn5CwqnyQEVpwk/+hdMPFX2P7TBNwRCwz7JLBpuLEa7NMvaXoUnwbQ2 zEEmC0EAw==; Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm3J-0004CJ-4j for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:00:19 +0000 Received: by mail-pf1-x442.google.com with SMTP id j8-v6so7432524pff.6 for ; Wed, 01 Aug 2018 01:00:02 -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=xe+ptcwA2jG1hIMUvqrzyq16x2eFJronfOhv7p2qODs=; b=BSn0QXX2DBmorvj8lIohJ2EXbUkxGkvf9BWUMTCPj0C+zsVYWHajL6qt2nEpp36NHU ivtJD62+dbbvT+3ey7XwnY86eKaD3mRNJG77m20YixjoQRDAp/A9VNVo5eYkommzuP+N dhKyRRvY41Udtd0ByQ+Jkr7UmtoDu4iGxn9qU= 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=xe+ptcwA2jG1hIMUvqrzyq16x2eFJronfOhv7p2qODs=; b=YzxfsYv39mPBmVo7XkwTvsrxy6VcvWS8l0SOgUeZmd+wuOkxkQyigKUF6atvak1Pzy FETuI/C5JVoUiGO9q9RSYlRTQ6bhJS4i0ASi9ZcZJO3MCbm385zVBn/zpedJMRGyGiZq OGo/Lqa/bHsU3xGrLMqCtwz2yYf8KdB+SWZ6TW80b+qvWRE5CRWcVOGkoIHfMwSvRxDa zJikXoxtjx87h05vBeouCNqA5Hcqu/P7OpixFoeK+J60cnSkK9uKGiVS48uovoEDBkKZ sFGHt6QrTNRc96YmavR/BM9SwONKKNOm65GAzb2xRUKngI1HL7cu6/5yHWaJpl8DYPub UL7g== X-Gm-Message-State: AOUpUlFMBZY0rNwAIl6p0TO9l8LWTF6k70piT/nvkDCerdkhUkG7LXSZ Huwj/UK6/ZMWjisWlW+59i6hRw== X-Google-Smtp-Source: AAOMgpfVXC7sXZf8XalxAV+Bt4OypVAPPERv9jx0sP5G5qzR9oVyBId3lcK0rrX19+7gHXDKuuKvrw== X-Received: by 2002:a62:25c5:: with SMTP id l188-v6mr25450400pfl.179.1533110400872; Wed, 01 Aug 2018 01:00:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p3-v6sm21954094pfo.130.2018.08.01.00.59.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00: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 v13 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Wed, 1 Aug 2018 16:58:08 +0900 Message-Id: <20180801075820.3753-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_090013_174426_DB5654AA X-CRM114-Status: GOOD ( 26.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, prudo@linux.ibm.com, 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(). With this change, arch_kexec_walk_mem() need no longer be a weak function, and was now renamed to kexec_walk_resources(). Since powerpc doesn't support kdump in its kexec_file_load(), the current kexec_walk_memblock() won't work for kdump either in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 ------------------- include/linux/kexec.h | 2 - kernel/kexec_file.c | 60 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 59 deletions(-) diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index 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..1073ef56a95d 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -501,6 +502,55 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#if defined(CONFIG_HAVE_MEMBLOCK) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK) +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + int ret = 0; + u64 i; + phys_addr_t mstart, mend; + struct resource res = { }; + + if (kbuf->top_down) { + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + &mstart, &mend, NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } else { + for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, + NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } + + return ret; +} +#else +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#endif + /** * arch_kexec_walk_mem - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. @@ -510,8 +560,8 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) * and that value will be returned. If all free regions are visited without * func returning non-zero, then zero will be returned. */ -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) +static int kexec_walk_resources(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) { if (kbuf->image->type == KEXEC_TYPE_CRASH) return walk_iomem_res_desc(crashk_res.desc, @@ -538,7 +588,11 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) if (kbuf->mem) return 0; - ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); + if (IS_ENABLED(CONFIG_HAVE_MEMBLOCK) && + !IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback); + else + ret = kexec_walk_resources(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Wed Aug 1 07:58:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551901 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 9DF231822 for ; Wed, 1 Aug 2018 08:54:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CDF128EBA for ; Wed, 1 Aug 2018 08:54:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8140A2B191; Wed, 1 Aug 2018 08:54:18 +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 2BC0928EBA for ; Wed, 1 Aug 2018 08:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type: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=JGxeOTTUiQ+upTAtbI9ERcaRALLtpr+J0A5SRXfAGIo=; b=WWe/glAtowEH7GoeNkCa+njlX5 vBD6iua05OSBYOktH9v69CfnDwo9QU7pGZfxDORLI9c/BOxvg+pmoGLq4FC2wgJF2cX/gIXF6KGxU /Sw8X1bDyzP9v7IK245p8hpvf9l51w4khG+jEQ7foPMYuPYUDc0waoSEKHOGq3keMU3gxcTX1ARHX DOvBNRkuxOa4nNiIBX+G/v5EmW0LjfemvfOe0rYI6BmerxWypfWymdWju3MJEEgnOKQH+fLdf5Xmp Mspzdwt6YIDA8dnJGRF/NlNBULtUw9loNSu6Bag+pusLZVv5ABMV0mnMbUBApCHTMxNlCvuqK2B6g aMzlTMtA==; 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 1fkmtY-0008IZ-79; Wed, 01 Aug 2018 08:54:12 +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 1fkmsj-00071q-HN for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Aug 2018 08: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=H9V/pRhzf1RnH7rtjNBLRuYtR4l5xIhl8He5yhS2iQg=; b=cehZGBwpS4wQXjhj51bP6uvbK 0zbKI5EZVsU9M3YTP2qfFZHxMEHVWbHscf5tqGbuKUXAdXKzlUKfla9TeIes8ppTDExVFvUweBWUl E4t9UWrIxnJ6qogSRgKEzr67rXEGEnCxuPIYLDJ10ELv8BETPhHf3aX1GLf5BgHTkamlpO1ickB9V XFSlIQxHz5tAq3yscrsx1++DQPxe0QviR9BmTSNaaFjA88D+69HS7kCzmhwCMRPq7gSnKEdxvekl/ lyWi1yC8/Vj+34+7G1LPjsjTOP8IY/gA7CXTMLb1vFf9qaAW74fcmUJDdWPL/ewZ3whL42X3ULwlh wW2MdF3rA==; Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm3T-0002PM-I9 for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:00:24 +0000 Received: by mail-pf1-x443.google.com with SMTP id e13-v6so7433449pff.7 for ; Wed, 01 Aug 2018 01:00: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=H9V/pRhzf1RnH7rtjNBLRuYtR4l5xIhl8He5yhS2iQg=; b=Dv6Ao5gbCEtv75PDFcno/cC/X0jP0Kp+YSXjdpVy2ycLWc28q9h03Q+dW3/n3iDhi0 WzYC/SbZjSVaYgsCyAp3rEq3HxWR1dl8CJD6iLTGOYG1WdBTT3Y1Sw3PQJGYMbFDj1va 4y0hNmbkjjjgQt24IaFB+VzuDY/MYvhdnsC4o= 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=H9V/pRhzf1RnH7rtjNBLRuYtR4l5xIhl8He5yhS2iQg=; b=MItBZ3XBKU6s6ikqhIkPYKgPBNMDhzqoM4lE/lgqkfG79DP4O6vJxHHM+DOvf3kcVw hqDejd/v5k2Zwrw764nE98U2eUxjcNoBMvnWoOKYCfxoSSAnp6IJKGXa6TMHc9cpLYVi bjKNmUxc1YdSRfWLn4TZA8DmFRvY8qIgR13FNZQGutz/xvVVywCS0GyVhEvtHyBj92Fl h5C+mt4JxIG5oi67zFtVaTWDhn8QULPEFvi+i8wCqryVKTsmsF/TAf7XyJ1tegef5Bvy zeCbHv67Mro6xQ4uLi0Ko01TIwmC8lPIUHOiRcyUQ5zmueeLnn6D23/scGT1whku7FTr K01g== X-Gm-Message-State: AOUpUlHejbN7xX47ka6PBMpvogQVcNBXXsSIaGHWAnV1ZXgrY14X4hP7 sY9zJbLqqzxrnIiR4nQ1EbnNPg== X-Google-Smtp-Source: AAOMgpd77a85zHpHjYF49EVfk4NZft8mM871fKOIxngiuOlnjLs07tPx8w70cZs9VRa0wjVguKXQ8A== X-Received: by 2002:a65:6398:: with SMTP id h24-v6mr23529895pgv.245.1533110409558; Wed, 01 Aug 2018 01:00:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h130-v6sm34714091pgc.88.2018.08.01.01.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00: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 v13 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Wed, 1 Aug 2018 16:58:09 +0900 Message-Id: <20180801075820.3753-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_040023_607888_E16937CB X-CRM114-Status: GOOD ( 16.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, 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. Cosmetic change: 0 to MEMBLOCK_NONE at for_each_free_mem_range*() Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- kernel/kexec_file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 1073ef56a95d..370d7d8ff27f 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -511,8 +511,11 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, phys_addr_t mstart, mend; struct resource res = { }; + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, MEMBLOCK_NONE, &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the @@ -526,8 +529,8 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, break; } } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { + for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, + &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the * range while in kexec, end points to the last byte From patchwork Wed Aug 1 07:58:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551829 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 97301157D for ; Wed, 1 Aug 2018 08:09:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 850C32AD2B for ; Wed, 1 Aug 2018 08:09:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 770122ADBB; Wed, 1 Aug 2018 08:09:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI 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 0C14C2AD2B for ; Wed, 1 Aug 2018 08:09:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type: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=f/n3kH2MbF4HAIGVotBLVlXbh+ O1VnD36crjq+jJy7P5eGycPVYf8gLkOyuxAAVKCSSmj/Wo854R8Z99uRi2frUMXvjjcJzKM5d5+FF y4cA6Pb0+qcly+uBwPZU1NJmgQ7HDQqFPY1to8o6YQTNOy0MpmggMLxY8PgX5zFurL3odW5mxmHxI 9fAqr9Pma6jbg7K/fXKkBm7nJ8VDiOc/ehwfRIdGKIzQqrB/MQPu5YLe4fDuWBWtTYW2S17oS4Jm+ j07E95bIQyEAO0J2blgJd8/xQLc7qkNrWxAKYq8p2Xh3+lDoZ77+Kf/WKLmLtS8EMsg7m4aS6u5bx lpXxUoPQ==; 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 1fkmCY-0001f8-CS; Wed, 01 Aug 2018 08:09:46 +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 1fkmCV-0001b0-RH for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Aug 2018 08:09:43 +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=fLowSY6mJuob0j2AasYwzHifbnb4+IvdIDuIYU6ROck=; b=gGSuYu8dcjvaS2fcI21g+mFbC BQSNFADAUmWxXQdT0AR3ek2ptElfJmxIKXh+sahsixAAYeI+DErHJ2d+PqY6HJiWZtGPIIeCQHY3o P4uXZ3PXG5U7kqtaj0N6LTQXFh8kGs7dtIljd7Vfqat5NqYz2QbywvH+PZkv1QRcNP4GzjfKbRwlx Q2CHRrIJSUWMAo4f5ySc+iQWD9aZCyud4yGfzr/h0RbCeVM1+xIygpG21DBcrA4TtFJPce3ZU5+AY oPTAGlLu5POE74nQMfG3NDcKYOjtDAfs/B1cnXAh2mnvu1hiuzrUaeEo1C7F0iyvrh4DBAKw705HI B1/qUPzcQ==; Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm3a-0004Dj-6p for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:00:40 +0000 Received: by mail-pl0-x241.google.com with SMTP id m1-v6so8399058plt.6 for ; Wed, 01 Aug 2018 01:00: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=fLowSY6mJuob0j2AasYwzHifbnb4+IvdIDuIYU6ROck=; b=H3hOaDS8j/Rt/AB/RW/jmcBKq5R0eDYWCPfojUYOtNVXx1+uDbbdhODFEqq7MTGhNX qx/PaUQr2nVxCGOFifDySvBW8chTOklnAvvijFuskd0+qCGdEh3wkiThBBNhugWphatt 08uTkcFREfQVSd7tfOheDtLEAWf35gAEHjJyQ= 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=V7m0o7N+P29dtSmFN4x/7ueywK9hWkswVpkC0NM/GfRk+00kTTqx3JvPyJJ3/i9Fg8 teGtYIlgyznFhKtVNg28zu5TrO1/M6bBPdFu4zpXS0fpzhVcefamBxCLAAF/M2s7XIaB bBX5CVP4rn35V5PPFtOt/9ncSvtfxKz1n6n1Sp162hZKfXnmBzyS/HtEaOlbtF1X2rGi 83HRtb5zHyFo+dzkcoY1wiwxFhUmEO2iWGZeQzxiWKxOkvhUfjU6sLx9IZo17CvQuOAY ozQe8kbbypn02s83eZYDjvQG7e0Vhn27P5qSi2eWFmnphh0KYSMdB03s014IgU3v7uEQ wxEQ== X-Gm-Message-State: AOUpUlGV6NXMOaBInJfoiB9l/eWC/F6NIc0CyY02RX5ChZYXtGhuKIUJ vFMoPcHBRyW3ys0s9vmWsHKZ5g== X-Google-Smtp-Source: AAOMgpc+AMz4Wr2BiJAzuy5IGekwnkHCchL43sXUOrLca36yNiRXcXIPjjWQK8KrSA+KJbMPG3zc7Q== X-Received: by 2002:a17:902:8f93:: with SMTP id z19-v6mr23221318plo.241.1533110418466; Wed, 01 Aug 2018 01:00:18 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e21-v6sm36306037pfl.187.2018.08.01.01.00.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:17 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v13 06/16] of/fdt: add helper functions for handling properties Date: Wed, 1 Aug 2018 16:58:10 +0900 Message-Id: <20180801075820.3753-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_090031_208282_C58E3C5E X-CRM114-Status: GOOD ( 18.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , 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 Wed Aug 1 07:58:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551899 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 D94631822 for ; Wed, 1 Aug 2018 08:53:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B412A00D for ; Wed, 1 Aug 2018 08:53:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBCF92B196; Wed, 1 Aug 2018 08: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 61B182A00D for ; Wed, 1 Aug 2018 08: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=M7HskRhvb7uKpaPyMVCFD+L3cPLioPqtP9kERY641aE=; b=tSxbKJQmaAdhMzTokFVisFeCqe /shwsDOH0tytyCiUNTNirnrYqJPEzyf/3fy5VCbwrEDcKa+B7sdYJN+KG0ystnopS46Ulcw0vKGuj 6pOrY5WmzD+DVwsAxUTayt9ovnOquYDZTvOGOMD4HjL3+yuVMPW5RfiMV5LX48Bog2sS+lpRtS45t uAH1DpwU5TG6Ct5+L83RDA6grbGPTBYbPPA0nXkKgBwkhTdHwZCx575b50SyKyTaijOFUOse4VGCA yFXF8VBDKqYMHrteLMVoQxEfTlfQjdJqCNc1kSEdsSIl7rNOc/p8PP5dHvkrts2R07uODWy0PQHgm Dn/+/MCQ==; 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 1fkmtF-0007uZ-7H; Wed, 01 Aug 2018 08:53:53 +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 1fkmse-00071q-Sg for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Aug 2018 08:53:17 +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=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=HkLOMlBNoumKbR7EJ3Qj5S8nB T/r6bfba2JHAUiqrOq+Z5kpJn9ftsQKghL2UoAIIxkLALzi7ITj2BIJchd3x4b6Rhund9QfKYNggo zRe11qlmjfkd2Jn1EOWn6/k1kLpG3+CM91jw9g2yq+Bf91oG0zeOUIWySJlxh4UeTM5gyceIn4P7c iMMy6Q+Qia19HaNAEFqotkEYZHrHtoIFSa6Wc5/drcSqsIhltuIMTay7nTrAv3/tMbZvA4s3riJcr Q7GDy7geNeHtEEvmhi5/V3xNMjnpEND67EQ6U15iM5TpJpVEBXeGKCJt+Y0MlcwwRuCOZIOOL1LLv 6RsYMIK3w==; Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm3i-0002Qn-UG for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:00:45 +0000 Received: by mail-pg1-x541.google.com with SMTP id y5-v6so10425225pgv.1 for ; Wed, 01 Aug 2018 01:00: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=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=WXTPUSFBAaJs3u7G5trMfLp5/+9YTEExILtRGBfs+IJe9vkg2fysxPnpMbwEl9flKD lmPW2tJJl3FVwZhHhcUrzrEVaAZzqxOAZdWJl0cn+FEKabJ78upRQuMSd/7x86eFBg16 Dw+52Me8FRGDb+FHMU+dnXOEvH1CuwLqEZdy4= 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=EyyN4qCsvzVz6+fwRPYpO97El4v15XtV5nDd3Ds3K+tCH1cGcnu0kaY0GjE2vOaQ2F VwbURVD4ub21zN0oFyM4HyZ0SquYpTJyGkzsy31IhZwOyOp4codNKsRKa3Kiv4iveGSM FgLA6+q8Ry5HF+ntdsmWWSNKL/lmldc8JD8dK3WsRUHzMVpnbymx1kG0niDnl/RZNERc MQaL0shofgxIIMipWaxckCorR2GOJbqtwM7ab3Lx3hUJ80MKBjr99adidonuMYuX3xMh 3PUUIxxu7bWNx1vtLJd6xgBja9kD1UhMaTK87GQASW1+Xnio0t8M99fn+1Yp/NNCgC9e Kczg== X-Gm-Message-State: AOUpUlHydQgwRgwFjaF5+FIfgGxpAzuVIT2zKRXC4JvSJdIBLGu+Ks4G 1zNJtEuLWtFCwm85HsEuiVxWbw== X-Google-Smtp-Source: AAOMgpdobygIZm1RoETsHCSnyruo4M9KJCTqNJ6PyyDQnV/jgKCBl449ugNcQM31Q7JMVyj6ulNUXA== X-Received: by 2002:a63:ba43:: with SMTP id l3-v6mr22801896pgu.295.1533110426434; Wed, 01 Aug 2018 01:00:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q78-v6sm30613415pfi.185.2018.08.01.01.00.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00: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 v13 07/16] arm64: add image head flag definitions Date: Wed, 1 Aug 2018 16:58:11 +0900 Message-Id: <20180801075820.3753-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_040039_017508_CC98EB4B X-CRM114-Status: GOOD ( 15.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 Wed Aug 1 07:58:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551913 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 399369093 for ; Wed, 1 Aug 2018 09:05:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 290C02B137 for ; Wed, 1 Aug 2018 09:05:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CD5E2B158; Wed, 1 Aug 2018 09:05:17 +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 1C9BE2B138 for ; Wed, 1 Aug 2018 09:05:16 +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=J3Ax2v8M2aIl0X2xcPBpUzdAHY fI6JpCvHIr9zSgTixN7j6fCixW+jEpoVLL2neoYWytDj+gJ8AmISTxvZjj+0Xnqa2L+5tx55PHqJO 15V9F6Ql79LKd+bCcMb0h/d6Jo8lDbpxfWE+3ZHtw4cxx/EVHxUjsAJ4NjvrMw4Ym8dF49sNoOccq t71q1m1zipE3mwyyfab0Zukj4pEk0sqIQtiDQ/eIV97SVBGgVhN1JhpntNuS9OyX5ZQA4KuI7f+r4 o2GMEtihtyUEzz/5Pl4HT2s+lPjpBTOMHmNRgfuSEGUnD2LhoNa40UZTKGzx0wvhwF72411s7f0Xy Etm65S8g==; 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 1fkn4D-00065G-3d; Wed, 01 Aug 2018 09:05:13 +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 1fkmsg-00071q-JE for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Aug 2018 08: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=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=U64RBrzn3ED3VBm7y6VDM1gmg p0KPvxCjykavAsnBV70MbENEEvvZpyEKW7AH1DG1Q+RJCrHItMU4oIN6YTHdDnaPYhvXOdmMaEEVZ hkAetj5yK+jkCZVsXufTvNom4s/8IGSW1JfxryG9A3sCDIH/bqWHhliOUJhhQSYIM4/tmmKT73eJt 9OqOOfQQDWNjmJ30J3rgCYCca0HYKdDPEbZdbXk/DOkrTuvp/3wI3mloOkBcQmtB3M4+IKO+8NkYj g8N8dx4RhvtbzSNVTP0Y3k3BEJBZJfxRvrxSV4D0Q0JNXYlYKDfJPRPWdMUr8ag1KGlIBzK4WgEjF V2JRiya3w==; Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm3i-0002RF-R3 for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:00:45 +0000 Received: by mail-pg1-x542.google.com with SMTP id r1-v6so10417911pgp.11 for ; Wed, 01 Aug 2018 01:00: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=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=MqqpJpBUvFp2lEvNJTwx9ZZ7YAwCgM8bOhVaSNxP2WpsLkQiPuslusADBhd+NT8pJh wY6LGOwsYr4Fmy4T8WtfjNNeb3rm4Z1Da/6snVjEoqCIyXPFkGz7syVHEB/P4EyEbfxX H40shOwKe4+WeIkwl0OBU1Mpl96yg9YBBBp58= 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=fLUFkiXAzc0zWytzB9bJmbEdZCHpkTg9k7CTHmZC+I/nlZEsTeBra6AH2I6ocbN1NV HCV31TIRzIviVyxNrUBEIs0oN6mEff/Zm+TatQuNaBYdrWndg15y05QhcwDLp2CUGjvW qO8BsvBZiaH1masPlyxSFsPkpebyw8OgT0fHxxWIwIZznRyotGEOBO1KqMtFUMX71mHE JtqpwiXfHJzO2fbtFoxPetq5Ik6wFP+atIyfip8zhY5zicmIWt5MapMLfkTaib7Tpd+H JHCvwmh71QbwnE6lC3LpGqR8llAsVrARk6ys9IVZD1yDM6GK6+wbzea1iSfZR1I1kgci Kzww== X-Gm-Message-State: AOUpUlFnw0B2gPrpMK7xgl4d8GgtF7odjEvTPN6tWlONge60aqU+0rpd qhud6wd2VWokUYA3wqgCc3J8sA== X-Google-Smtp-Source: AAOMgpeD+cvoWhQ0ma8Us5tu7BdovMGDcguPAG7TL1pU4A0ltdns1oC7DcmEkIZIvnBKU9N3eloScw== X-Received: by 2002:a62:f610:: with SMTP id x16-v6mr25875846pfh.169.1533110434107; Wed, 01 Aug 2018 01:00:34 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v8-v6sm9357075pff.120.2018.08.01.01.00.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00: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 v13 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Wed, 1 Aug 2018 16:58:12 +0900 Message-Id: <20180801075820.3753-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_040038_944180_3105971C X-CRM114-Status: GOOD ( 13.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 Wed Aug 1 07:58:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551897 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 6CAE51708 for ; Wed, 1 Aug 2018 08:53:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BC822A00D for ; Wed, 1 Aug 2018 08:53:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E9E32B194; Wed, 1 Aug 2018 08:53:45 +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 E21612A00D for ; Wed, 1 Aug 2018 08:53:44 +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=LWBLemz9smKlBQxgMkYHuz7JASv1qAW/xe7j7uClVQ4=; b=RGTguJX4xG7uGmlkO62myYKmZt wToUzSLjReUfadk80wrLFPYTvvnvRxfQvK0APtH+man/vf6LkqeQaYntP7Zgwj6+b91nI6+IVCwtb 9K51YiMaWgyxPz4S6NCSqaV6+v5rUdpdZP+u3wdFCUT5x/IIZsw+HiVwl7+zjiKNigUd9Ozi5UWaf e06hYURzVBTn5Db15wJzpNJG/Z0M2pCaZmsgDNM59kzWE536mq+Hv/siVO9alH1zoANug3ZAe+fpX KKhuTRMAA4BVGdSYxoSae1Bi0vBFcEq4KoVVj5TvccTnXo5qDVI9/LNUqrHROEc1zQo8LETj71YVK odCnjLJA==; 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 1fkmt3-0007e4-5i; Wed, 01 Aug 2018 08:53:41 +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 1fkmsd-00071q-Cw for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Aug 2018 08:53:15 +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=zriOn+WEEg9EazqAOYJi2TzU71K/MV/o6JIIMj34rno=; b=fZrfKMPvNGBcbTQZ8748cordw xlbKjt1bUzCehuHPjFi5lS8If2w8ANNNun3UdBFIoCDq1LTvoYSZ4/MM+cf3f274yo0E86phg+Do/ 1qxIP7wFOUGugG0bu308CBRp+7r+Jgun1u7WxrWxJ29mLvs2OFmvErlCOH2SD6rXHZonxuW+vdPJo E7SM/3w76Dbh/I9Hc1d1BNsKRVVXZmnLtoJHb+nJeiVz68Qr0d/j6FNxyOS1mXK0geJz+HI/U6/Q7 s92LzJfqC9R+TgXNUJCZlBWDpzQmGcI1JwvXhW0Yw76/bGQD5A+wkZGI1dE4/5AulZGQ2NvCLnxad WCOpOowpA==; 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 1fkm3z-0002Sy-7h for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:01:00 +0000 Received: by mail-pg1-x543.google.com with SMTP id n7-v6so10427564pgq.4 for ; Wed, 01 Aug 2018 01:00:44 -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=zriOn+WEEg9EazqAOYJi2TzU71K/MV/o6JIIMj34rno=; b=bvGOQIkvBmDgcU5RI5ZqVEOSB5GvKJdRU1fhcJKLV93+axy/cZ1PiiD3NNZDl/ziPl /6/wtfG6wc1FpL/b8nhxTUIIZ/s1R1Z5dokBhrcy8Tv/u8vTLYP9e/byweReQ7xqAfTx JkW3v0bv6J4jpyBeUp9+Xx+wJceiTDXkts/F4= 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=zriOn+WEEg9EazqAOYJi2TzU71K/MV/o6JIIMj34rno=; b=UNbktyL6/snykvf4cH17V0W2QtUpy9gQU/GrtNHB8ZeGslkgJLh9ELTttaoocTdCEm MvtJ32xT+NmDk9ZEE9ellWlzDD1V4Edbywr54CSjAPRuiWwLn28lKE/QTOpATg+j1FT8 OkOR3HZI7GdTzMipOAevnGvwICZpnPu/axrVzZWNc+T5b9SberY4g4W34b+9iZe+z1h6 /MMiDqRHK8G8kYYniFYspLK+8xaT4qJflm/H6xBiR4xY9d6QbTWHmBauHbEAOQlUwHr1 w0sXFMGTbwtveWmu8vYskookiZlsNv6CcMJGIGFfeWdRyq4hH0K3uSrEX5TkjWKb7eFo vD7Q== X-Gm-Message-State: AOUpUlGikqx5OnQNaT68bsB1Tw3hIOlWJ4rXZ+e4zYLktBLfxtUKb/Ey LyK7mUrN2V8do/JhaL5TmVZn3Q== X-Google-Smtp-Source: AAOMgpdHFSgMIc0zWHMtsZGoCFGeEUhlkYGC6U/A20hTg3Ps7VQI585rzqHHoAHkb4/8n1FRB7QHaQ== X-Received: by 2002:a63:5d58:: with SMTP id o24-v6mr23983744pgm.349.1533110442712; Wed, 01 Aug 2018 01:00:42 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g5-v6sm5201850pfh.63.2018.08.01.01.00.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:42 -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 v13 09/16] arm64: enable KEXEC_FILE config Date: Wed, 1 Aug 2018 16:58:13 +0900 Message-Id: <20180801075820.3753-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_040055_294720_60973253 X-CRM114-Status: GOOD ( 18.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 1494d5cfd681..5988e767526f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -852,6 +852,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 95ac7374d723..8f1326b2d327 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -49,8 +49,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..c38a8048ed00 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; From patchwork Wed Aug 1 07:58:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551801 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 15010157D for ; Wed, 1 Aug 2018 08:01:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04B8E2B0B0 for ; Wed, 1 Aug 2018 08:01:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECC8B2AE86; Wed, 1 Aug 2018 08:01:20 +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 59E682B070 for ; Wed, 1 Aug 2018 08:01:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type: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=IMICTPrAm4ba1ADECrLPDPQFaCNNet/OWlCyEyD+uCg=; b=ryA4r2sYsNgPqCTnSu9Cuu9kHy mLPtFTnawi5IRC7iPc/yoOu5zVPdFMmc3IPw4FvkGYTnGpe5H0P9zktYFY2eqISZdzEw0VgTcoQkX qvdA0VPI0aO6AZp0Cpg91I8MVpQdLFi54ng86GcejeqDSX8b4Ipn/iRTaxYqH+PFcRnZh6SejpVAw f8kf1Q1u1PfvZMF+L0qNRYJ1FxbiZuv/D0f1FanRTMvy/EZl6Vd/okbPyhgEX96QyeSCHysK9wvc/ b22Ma5kgyAn2t3SuJT6DAaHzzNfHJ+/e1hpnpwDlzRdy0918wvqKcib6fICHesLpTqrCBdTv3qhq6 gM6LiAMw==; 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 1fkm4J-0005R9-L9; Wed, 01 Aug 2018 08:01:15 +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 1fkm47-0004hP-3D for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:01:13 +0000 Received: by mail-pf1-x444.google.com with SMTP id l9-v6so7435245pff.9 for ; Wed, 01 Aug 2018 01:00:53 -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=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=ThvUzo7N/mywR8+KG5HpBwmfPqMjQw/6kSvpVKlXOIHX/bZTgn77FYY3C+4v+WoN8S khpEPvhAPCWbA2ZWcnBoAKeNeQBJ9WAJ/7UotxTYhazOzIa9QFjuXO09oTOyM5HY0sSn IYm+vXl4osUnWA6IwsewhJSEd+BqWDipxUxsU= 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=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=ENSGsHeCRlbIN3ojyETcwdmi2ushAwel23axIGgbJ7roj8XSwZUUxeP6PPGa+fFnnd kreS1qfStKWx7+0bTYH8N1TfXlDARVNdwnu+sQwJAMnPJW7vzHEeon+pqjzj0F4H00U0 ESzV1ZnJLnVM6/snpRtVwNEAL5d3om7VMsYMbpNuOuc3kiF+HGo7+crcN67NscJ0tD4f SBuvG3ol4XPieSmJ0TGhRKISPY/PjN7qtSvSsjZ0/3zH+EAyQZhWOG4hsyaRQ6rSt6lI 3W/wgXsn4r4wff82ViIa+gkeFSSBJ9EZQ1U5S6cLATTg8jgwZNWLMIY19A5eMnEWY4di YkbA== X-Gm-Message-State: AOUpUlELxeE53GeXHB0JrbI19zp3CgDpQM+TRfFoiDBBfpyoXRj6/eFk yxx655gcCzxcBCheqW5NHhUOqg== X-Google-Smtp-Source: AAOMgpdsGh2kwqs5NcMjPEp0kvt0vng6m6BborLbcj3m4dPa+m7rSiucJowDcATFqFKV8sDN7PHXaw== X-Received: by 2002:a63:5542:: with SMTP id f2-v6mr24034312pgm.37.1533110452603; Wed, 01 Aug 2018 01:00:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t76-v6sm25277361pfe.109.2018.08.01.01.00.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00: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 v13 10/16] arm64: kexec_file: load initrd and device-tree Date: Wed, 1 Aug 2018 16:58:14 +0900 Message-Id: <20180801075820.3753-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_010103_238295_C48ADE63 X-CRM114-Status: GOOD ( 17.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, prudo@linux.ibm.com, 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 | 188 +++++++++++++++++++++++++ 2 files changed, 205 insertions(+) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..157b2897d911 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,23 @@ static inline void crash_prepare_suspend(void) {} static inline void crash_post_resume(void) {} #endif +#ifdef CONFIG_KEXEC_FILE +#define ARCH_HAS_KIMAGE_ARCH + +struct kimage_arch { + void *dtb; + unsigned long dtb_mem; +}; + +struct kimage; + +extern int arch_kimage_file_post_load_cleanup(struct kimage *image); +extern int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index c38a8048ed00..f53f14bd1700 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,200 @@ * Copyright (C) 2018 Linaro Limited * Author: AKASHI Takahiro * + * Most code is derived from arm64 port of kexec-tools */ #define pr_fmt(fmt) "kexec_file: " fmt +#include +#include #include +#include +#include +#include +#include +#include + +/* relevant device tree properties */ +#define FDT_PSTR_INITRD_STA "linux,initrd-start" +#define FDT_PSTR_INITRD_END "linux,initrd-end" +#define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { NULL }; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb); + image->arch.dtb = NULL; + + return kexec_image_post_load_cleanup_default(image); +} + +static int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + void **dtb_buf, unsigned long *dtb_buf_len) +{ + void *buf = NULL; + size_t buf_size; + int nodeoffset; + int ret; + + /* duplicate dt blob */ + buf_size = fdt_totalsize(initial_boot_params); + + if (initrd_load_addr) { + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len(FDT_PSTR_INITRD_STA, sizeof(u64)); + buf_size += fdt_prop_len(FDT_PSTR_INITRD_END, sizeof(u64)); + } + + if (cmdline) + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len(FDT_PSTR_BOOTARGS, cmdline_len); + + buf = vmalloc(buf_size); + if (!buf) { + ret = -ENOMEM; + goto out_err; + } + + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + nodeoffset = fdt_path_offset(buf, "/chosen"); + if (nodeoffset < 0) { + ret = -EINVAL; + goto out_err; + } + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop_string(buf, nodeoffset, FDT_PSTR_BOOTARGS, + cmdline); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_BOOTARGS); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_INITRD_STA, + initrd_load_addr); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_INITRD_END, + initrd_load_addr + initrd_len); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_INITRD_STA); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_INITRD_END); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* trim a buffer */ + fdt_pack(buf); + *dtb_buf = buf; + *dtb_buf_len = fdt_totalsize(buf); + + return 0; + +out_err: + vfree(buf); + return ret; +} + +int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + void *dtb = NULL; + unsigned long initrd_load_addr = 0, dtb_len; + int ret = 0; + + kbuf.image = image; + /* not allocate anything below the kernel */ + kbuf.buf_min = kernel_load_addr + kernel_size; + + /* load initrd */ + if (initrd) { + kbuf.buffer = initrd; + kbuf.bufsz = initrd_len; + kbuf.mem = 0; + kbuf.memsz = initrd_len; + kbuf.buf_align = 0; + /* within 1GB-aligned window of up to 32GB in size */ + kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + + (unsigned long)SZ_1G * 32; + kbuf.top_down = false; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + initrd_load_addr = kbuf.mem; + + pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + initrd_load_addr, initrd_len, initrd_len); + } + + /* load dtb blob */ + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, cmdline_len, &dtb, &dtb_len); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + kbuf.buffer = dtb; + kbuf.bufsz = dtb_len; + kbuf.mem = 0; + kbuf.memsz = dtb_len; + /* not across 2MB boundary */ + kbuf.buf_align = SZ_2M; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + image->arch.dtb = dtb; + image->arch.dtb_mem = kbuf.mem; + + pr_debug("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kbuf.mem, dtb_len, dtb_len); + + return 0; + +out_err: + vfree(dtb); + return ret; +} From patchwork Wed Aug 1 07:58:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551803 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 D710A174A for ; Wed, 1 Aug 2018 08:01:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5D6D2B041 for ; Wed, 1 Aug 2018 08:01:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3E412B045; Wed, 1 Aug 2018 08:01:54 +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 292632B083 for ; Wed, 1 Aug 2018 08:01:54 +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=3mGOOxFW939CeyXJdxaLaxiZboU58JkpkgqkZOx8Sus=; b=O25UQ5JY4mLw8A7oMR1mkrLvvZ Wr51tyI99QEjDNtX5Ausfoy7CmHfIGKepSo6g6093cQjjjXPnKtRhPdDG6ebgVCwjGoo7ukTsqFqS VPrl6WKh1SDQztxUfw7ltfHqMxa3l9xiQ6UlLAGDj7BxWV1tzQrrZNABdW++GtWIZGH8bFunwje8l XduotfYM1C5AZCTXojKZEMmAaoP49bPuC4X4aOZIiGGInhR9BlokK6JP2gyy2bNtbofMtX0gtxGkD vvx6NnAGi4VW2trBmxCbSqnWf+7S1X8Uog6qmEeCCsRj+akXU20i33GJvXBjtCV1wPET9wK9SUI58 W4zcuwKQ==; 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 1fkm4o-000634-QW; Wed, 01 Aug 2018 08:01:46 +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 1fkm4F-00056U-9e for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:01:21 +0000 Received: by mail-pl0-x244.google.com with SMTP id w3-v6so8410846plq.2 for ; Wed, 01 Aug 2018 01:01: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=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=NwmscwYWhqZON8CZseKhpgwawplUbNJN7/b2gDIO+S3brOWLLrCVuT0HsDWjOI5tAf i/izdBfGKLCi7iukZUaomqzIUFXKMYv9aNs+WSxYU3bvXXU8fxmyb1YXeafnCHhd8oFw StriFjJ5JMjSHdVXfWvZ79jYjFP4OXFHYXgB8= 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=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=ODEjXCS0P4Fq5ekzwcIO58JjSuPnwN0GX7UIiC0TfQrn8DX8Lucb/quc2chPLiU1G1 L5AqNhG7lomQwOHOBvKt6OQ7F0AlmlTbauJqkeSadsePoMRzluEBtfhD+kvOxM8rf41B kB1hLSqrC7DFCgD75PYyt1uhhdISV0ksXzXP+f6RLVltFTKFUd/vqYVITkbyrx3zlvFV KptKSp1inju+0PMpIsQ4lzoGOPS5QqKTYmVWE3MytHJRJ1t7c5iqGlzSq+m2DLIhCMKn 8l+kCuWOXlwaIVdChWZnP7+Q1owmQMTkLMvl0oCPHyTbDgQln/gwZXYXOWzH5zDZ/BCf XJ7w== X-Gm-Message-State: AOUpUlHO+1baIY2Sk5jFSmeIl7MKK/LjP13kommWx1Lpd1ioB8PU+V7r 0C29PepGr+vJwA0Po2gIOq6QmA== X-Google-Smtp-Source: AAOMgpf2ju1RI4PpxT/qDFHLf+d/1AsAffsW46/HN6hBAHfVD6jPpBKGAI9XmbeFoMY+HC8cMCa/bA== X-Received: by 2002:a17:902:b08d:: with SMTP id p13-v6mr24237716plr.0.1533110460349; Wed, 01 Aug 2018 01:01:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w16-v6sm40801764pfi.101.2018.08.01.01.00.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:59 -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 v13 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Wed, 1 Aug 2018 16:58:15 +0900 Message-Id: <20180801075820.3753-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_010111_341864_FD209CE4 X-CRM114-Status: GOOD ( 18.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 157b2897d911..5e673481b3a3 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -101,6 +101,34 @@ struct kimage_arch { unsigned long dtb_mem; }; +/** + * struct arm64_image_header - arm64 kernel image header + * See Documentation/arm64/booting.txt for details + * + * @mz_magic: DOS header magic number ('MZ', optional) + * @code1: Instruction (branch to stext) + * @text_offset: Image load offset + * @image_size: Effective image size + * @flags: Bit-field flags + * @reserved: Reserved + * @magic: Magic number + * @pe_header: Offset to PE COFF header (optional) + **/ + +struct arm64_image_header { + __le16 mz_magic; /* also code0 */ + __le16 pad; + __le32 code1; + __le64 text_offset; + __le64 image_size; + __le64 flags; + __le64 reserved[3]; + __le32 magic; + __le32 pe_header; +}; + +extern const struct kexec_file_ops kexec_image_ops; + struct kimage; extern int arch_kimage_file_post_load_cleanup(struct kimage *image); diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 8f1326b2d327..8cd514855eec 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -51,7 +51,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..d64f5e9f9d22 --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kexec image loader + + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + */ + +#define pr_fmt(fmt) "kexec_file(Image): " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int image_probe(const char *kernel_buf, unsigned long kernel_len) +{ + const struct arm64_image_header *h; + + h = (const struct arm64_image_header *)(kernel_buf); + + if (!h || (kernel_len < sizeof(*h)) || + memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) + return -EINVAL; + + return 0; +} + +static void *image_load(struct kimage *image, + char *kernel, unsigned long kernel_len, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct arm64_image_header *h; + u64 flags, value; + struct kexec_buf kbuf; + unsigned long text_offset; + struct kexec_segment *kernel_segment; + int ret; + + /* Don't support old kernel */ + h = (struct arm64_image_header *)kernel; + if (!h->text_offset) + return ERR_PTR(-EINVAL); + + /* Check cpu features */ + flags = le64_to_cpu(h->flags); + value = head_flag_field(flags, HEAD_FLAG_BE); + if (((value == HEAD_FLAG_BE) && !IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) || + ((value != HEAD_FLAG_BE) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))) + if (!system_supports_mixed_endian()) + return ERR_PTR(-EINVAL); + + value = head_flag_field(flags, HEAD_FLAG_PAGE_SIZE); + if (((value == HEAD_FLAG_PAGE_SIZE_4K) && + !system_supports_4kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_64K) && + !system_supports_64kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_16K) && + !system_supports_16kb_granule())) + return ERR_PTR(-EINVAL); + + /* Load the kernel */ + kbuf.image = image; + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = false; + + kbuf.buffer = kernel; + kbuf.bufsz = kernel_len; + kbuf.mem = 0; + kbuf.memsz = le64_to_cpu(h->image_size); + text_offset = le64_to_cpu(h->text_offset); + kbuf.buf_align = MIN_KIMG_ALIGN; + + /* Adjust kernel segment with TEXT_OFFSET */ + kbuf.memsz += text_offset; + + ret = kexec_add_buffer(&kbuf); + if (ret) + return ERR_PTR(ret); + + kernel_segment = &image->segment[image->nr_segments - 1]; + kernel_segment->mem += text_offset; + kernel_segment->memsz -= text_offset; + image->start = kernel_segment->mem; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kernel_segment->mem, kbuf.bufsz, + kernel_segment->memsz); + + /* Load additional data */ + ret = load_other_segments(image, + kernel_segment->mem, kernel_segment->memsz, + initrd, initrd_len, cmdline, cmdline_len); + + return ERR_PTR(ret); +} + +const struct kexec_file_ops kexec_image_ops = { + .probe = image_probe, + .load = image_load, +}; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index f53f14bd1700..05fb2d4e6fef 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -25,6 +25,7 @@ #define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Wed Aug 1 07:58:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551805 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 7BDFF174A for ; Wed, 1 Aug 2018 08:02:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C6D32ACD6 for ; Wed, 1 Aug 2018 08:02:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6092D2AF3F; Wed, 1 Aug 2018 08:02: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 53F872ACD6 for ; Wed, 1 Aug 2018 08:02: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=ddDYqYhkY2b4/OE/tYU2yLOEaPe7TL45CNYjveHsKKo=; b=Q+zMX63mxVETJ/W8HXFBUBYtWs oKBKpsbt9LoKOobvfGxDJIN/7wKcqw0t2OdXVGTQ1U614k4bVd3TclSnpWeL6w82unohzhsW9mYfu 5ZQef4fk/f7kd4AXBMTVgxVTye/nkHE5WpjF1PLegqxkoSOnoagiB9x4wsVZJv1UOhtTsfetTkzUG MW3eF/vjLAtlSxPTz6Dp3HohrPWfKYdL5/A6Zk3zX62/0XcWdTUf5r75z30QuIiTl6Nu/AhEiLXEM cPL+CFlwFEGwKMj+35wbVOXfWv/KkFbnrvTx8MQbwOiZrtv2vNR6jgA0L+sfHfOwJOrqHBafZZYZW CCgUiaVA==; 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 1fkm5B-0006T5-Fp; Wed, 01 Aug 2018 08:02:09 +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 1fkm4M-0005QD-Rw for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:01:29 +0000 Received: by mail-pl0-x241.google.com with SMTP id 6-v6so8408428plb.0 for ; Wed, 01 Aug 2018 01:01:08 -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=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=gta+etzeWi3Nx5jjttTNJzlJ8GPAKnWoahb+v1yzW24La5bc/QpxtkdsLbAT8GYsSq StlHZBWhGxPUkMd/8inqZlem6+PdGQxcTyvFlsa4kpHUMvHWYgr9LrK/BZq2g6NfW2qk kZYE8n4WhnY8IrlwHxemXTiFEXtDIcwMV1GBs= 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=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=m8zdu5VfMEnuI/m4zQUaK4DkHTDJl+4rh/BmZqTn0MvPzmXQko0pZEgUgBkp+AbGxi 5qS7AS3Sba+eBYS/V9j8hFBkvNHa33iAzsC+HsdNxbmppbfnRItdaftNKv1zRm3SAjPI eWWQjnZtlacr+Nzvv/YtM5D8EATdvWkosQf4MQlOYpmNBfIe24+GiSdhE4Bpd/eLIq0G 0fLbwlyxYLIwEgwMh56RwwayAd9FNHufMYWnEOMlLr4gaYRTZn8/aYYaEXj7F8gx/KRO WFL15pNmRgYkzZd4j3uqUPr5ugT1kZKcQn5PWgHIwthZ9ut0rO1Dqg7hT6yvsPdEEIpH OxOA== X-Gm-Message-State: AOUpUlFdmFfXRKusGg95sHJ1t365M7onspyt/8aGPNQdOPURo6u9RpWt zXRbJCzCP5FhsHuYx1/3eT1BjA== X-Google-Smtp-Source: AAOMgpeKNO0I2Rhv+3odzHqbyKG6X4I685ZSgSqwfQJoURHNOezVfkrjwPgqIsYqUx7NPlAj/5vtYQ== X-Received: by 2002:a17:902:b28:: with SMTP id 37-v6mr23369526plq.337.1533110468327; Wed, 01 Aug 2018 01:01:08 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z8-v6sm21955997pfe.163.2018.08.01.01.01.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:07 -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 v13 12/16] arm64: kexec_file: add crash dump support Date: Wed, 1 Aug 2018 16:58:16 +0900 Message-Id: <20180801075820.3753-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_010119_281215_1399B11E X-CRM114-Status: GOOD ( 20.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 | 4 + arch/arm64/kernel/machine_kexec_file.c | 113 ++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 5e673481b3a3..1b2c27026ae0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -99,6 +99,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb; unsigned long dtb_mem; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_mem; + unsigned long elf_headers_sz; }; /** diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 05fb2d4e6fef..ecaecb122cad 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,10 +16,14 @@ #include #include #include +#include #include +#include #include /* relevant device tree properties */ +#define FDT_PSTR_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PSTR_MEM_RANGE "linux,usable-memory-range" #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" @@ -34,6 +38,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb); image->arch.dtb = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return kexec_image_post_load_cleanup_default(image); } @@ -43,12 +51,29 @@ 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(FDT_PSTR_KEXEC_ELFHDR, range_size); + buf_size += fdt_prop_len(FDT_PSTR_MEM_RANGE, range_size); + } if (initrd_load_addr) { /* can be redundant, but trimmed at the end */ @@ -78,6 +103,22 @@ static int setup_dtb(struct kimage *image, goto out_err; } + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(buf, nodeoffset, FDT_PSTR_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(buf, nodeoffset, FDT_PSTR_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(buf, nodeoffset, FDT_PSTR_BOOTARGS, @@ -135,6 +176,43 @@ static int setup_dtb(struct kimage *image, return ret; } +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + unsigned int nr_ranges; + int ret; + u64 i; + phys_addr_t start, end; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) + nr_ranges++; + + cmem = kmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL); + if (!cmem) + return -ENOMEM; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) { + cmem->ranges[cmem->nr_ranges].start = start; + cmem->ranges[cmem->nr_ranges].end = end - 1; + cmem->nr_ranges++; + } + + /* Exclude crashkernel region */ + ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + + if (!ret) + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -142,14 +220,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 Wed Aug 1 07:58:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551807 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 5D61C157D for ; Wed, 1 Aug 2018 08:02:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A4602AD13 for ; Wed, 1 Aug 2018 08:02:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AC322AE86; Wed, 1 Aug 2018 08:02: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 BF16C2AD13 for ; Wed, 1 Aug 2018 08:02:30 +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=Yu1kp3ja0qZGv9b20TLYi2FgjBScBvweBt/6FjfzXA4=; b=TdbDmKtulcZyrdY69CU6GfZyrp S9VOkkOlpwS6pMp1SCLdxHkMF/z/dr8wH8VnZlJ9T2dF2nvZyHztdkzbff+Fydv/GH4iVYbI+W864 fd6mP09PGDzbEhDmR+oo/apkKqzGgIVrLD5fJJBxE/HiarcHgRagydPTufqiu7uB3WUyaX8u3wsPs 4kppvXRYYkHcSflG56OcpTPEkJBNo4b0BjxX0rWrdMLsZbTDbohsmxw9svFI1evJ73iU6oNvYdeT6 7078iv4TYv2BTF/6+n67b/dIehRIVQP9H3Z8bTACKFH/GW/Wn7dArMEMp8I0cyU9DzeGCp9hISxxM NzkI7MYQ==; 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 1fkm5P-0006kF-R8; Wed, 01 Aug 2018 08:02:23 +0000 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm4V-0005SO-9Q for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:01:31 +0000 Received: by mail-pl0-x242.google.com with SMTP id d5-v6so2872471pll.4 for ; Wed, 01 Aug 2018 01:01:17 -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=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=bxrkEBZXNqcYnVXYfofTMl+wEyc+V6K+tsKOHnDes2qAy23Bi/unqeMP5fXb4rwcwX jVhm3yJfolblrN6UpfKf/bEeYNx0fTKZmy/2YBAmlaKMiOzPB92Y9CvXIGkgghi5uNAr A0h7JdHDtZd9yquPU8REl7XYTwXvkyUm6fbZs= 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=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=dSUt/AaCbzYpwu5abgkbM1E8WVx4vvYlcLFO7mVXqZZYoBfB/hG7BHTpTTWgpyUqTI HnacbJgmtJ4TdtnFNwoj7e0HIEvh9B+Y2x8CpFsuF21ezqzPu3+40UxzQlYOPJBRXr1E QCf+fioY7ZXesu6R9R6Bjh/pN6U+r6GTVpnfwMiNVRH6ekhzOOVy+8bntZBB8yLAUWaU dzJ+xklVL04vc6GGNzJ4ryUA18BHq0cJjRL5OijNXV7FVydkPcqv0dSfDYMn/69cGnPi s1gK3LlUfMYyTGKAL4iEBVcjMlqcPqbYo98jfZMLa9UvkVQZcWPKgpaihhGllW8eGPFj PE4g== X-Gm-Message-State: AOUpUlEA6DXz40Pc3eQq0fQFsCa467EvZPRumCNVdIvy8VxTTZXpxncF zXELB2UnFFh/RYGzHVWj+TxoRw== X-Google-Smtp-Source: AAOMgpdNDS7dxza00mnHJBRqeP7/crHoMzydftC4c8sfs/O5oumdgP4OVAI0buW/FOczJNWBE6jAAw== X-Received: by 2002:a17:902:bd93:: with SMTP id q19-v6mr23484079pls.238.1533110476812; Wed, 01 Aug 2018 01:01:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v3-v6sm52649116pgb.54.2018.08.01.01.01.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:16 -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 v13 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Wed, 1 Aug 2018 16:58:17 +0900 Message-Id: <20180801075820.3753-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_010127_919249_08550F8B X-CRM114-Status: GOOD ( 15.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, prudo@linux.ibm.com, 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 f6a5c6bc1434..c63c355e2f18 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -212,9 +212,17 @@ void machine_kexec(struct kimage *kimage) * uses physical addressing to relocate the new image to its final * position and transfers control to the image entry point when the * relocation is complete. + * In kexec case, kimage->start points to purgatory assuming that + * kernel entry and dtb address are embedded in purgatory by + * userspace (kexec-tools). + * In kexec_file case, the kernel starts directly without purgatory. */ - - cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, 0); + cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->arch.dtb_mem); +#else + 0); +#endif BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index f407e422a720..95fd94209aae 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,6 +32,7 @@ ENTRY(arm64_relocate_new_kernel) /* Setup the list loop variables. */ + mov x18, x2 /* x18 = dtb address */ mov x17, x1 /* x17 = kimage_start */ mov x16, x0 /* x16 = kimage_head */ raw_dcache_line_size x15, x0 /* x15 = dcache line size */ @@ -107,7 +108,7 @@ ENTRY(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, xzr + mov x0, x18 mov x1, xzr mov x2, xzr mov x3, xzr From patchwork Wed Aug 1 07:58:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551809 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 0C3A0157D for ; Wed, 1 Aug 2018 08:02:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1323285E1 for ; Wed, 1 Aug 2018 08:02:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1521285FD; Wed, 1 Aug 2018 08:02:45 +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 3E5A5285E1 for ; Wed, 1 Aug 2018 08:02:45 +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=JmNrMK5I44JbPj29EPuIPBH6FW pLAMtCH9fg1pe3jnfg6TemrYBJZvmNgdLnbO0y+bUV/04byTFy9ivbFlBJCvYGK1CMdDfSqlKUdaQ DEcIX/rHPhNT941m0dngV8Lr20sHNvQ3XlmLZ0MYzQu3Hapbq3lKf91Dja6MQdJBfTtZG4bdmsqdB nyiwcDn05noE3Ky4X46Ua6PYsiiEiKcAeUSKbm8/Mi/Irvblyn7ny/FSDIcHbR2KI0tDRAENvppFF 1LZgsquIs3i6URtBeNBMx2Vj5Kalcvx7R1bXZfcrcOQVD6YCD+PrZtsXYBtOoumY2wznEZbACyPmL ScngbtwQ==; 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 1fkm5f-00071u-1T; Wed, 01 Aug 2018 08:02:39 +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 1fkm4d-0005ay-8Q for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:01:45 +0000 Received: by mail-pf1-x443.google.com with SMTP id d4-v6so7206379pfn.0 for ; Wed, 01 Aug 2018 01:01:24 -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=ZLy7xhwVoIk2JGm9se9fVuenhAyqRTXpFLb3RWBSFKDbrsdyjwlSdoj3/mNPxXm3Pp ParJ6WCLkg44t7OIzVyYXHtfPrCIvmj6Dy+8H27lKfdaa9VMlXMX3zv7sJcs5eOzE1ip UCnt9sSLtloaO862KDPWAqGU33k02X9kuCryM= 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=N/L1BCuu06WGo1BOLdosGY3pB0r6b2PVVHyLPP5CZATLHL4nRmSkV3nETIxKyAVx8W v/1pHD1Jl6jT48nHIJhTrBxXoh20Kp90INltGU+6K44L0SBmJqfrb/OsQJmS2Qh4ID+J FfTFfivz7aV6PQa/mCZ5lVStRQds+8BJMedey4JebuExpUo4mFudADM9PYVOeXODajmK guYNChG0xqWLhltS3gBFyFYQqdT68CAiqyfwZrWv64sFR2+FHZ5FLTKW1F5b183aF/yB GNk5aMWY9AGhzVCV7wvOHfuz95UIVZJVSmzUYd7V14cp/yD4OTdtqFkeDQ15tpJyIZVW OCGA== X-Gm-Message-State: AOUpUlGOIDtlLXlrJGcrG7gmIYIOxh3awPYT7NSR7HbCqVOSiEtv9tT+ fCCfNKIWlpPdeqIpw4mnmwgdsQ== X-Google-Smtp-Source: AAOMgpf5JZcnlp+RA9WoHn/IsSQXJ+MkIZi37U3PnMaIOum257RI6Al2wgE8ddTOqBn+jXl7x5cKww== X-Received: by 2002:a63:c00b:: with SMTP id h11-v6mr23123341pgg.279.1533110484291; Wed, 01 Aug 2018 01:01:24 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h24-v6sm12255971pgj.10.2018.08.01.01.01.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:23 -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 v13 14/16] include: pe.h: remove message[] from mz header definition Date: Wed, 1 Aug 2018 16:58:18 +0900 Message-Id: <20180801075820.3753-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_010136_030002_23FFB8F2 X-CRM114-Status: GOOD ( 14.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, 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 Wed Aug 1 07:58:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551811 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 B0776174A for ; Wed, 1 Aug 2018 08:03:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A09A1285E1 for ; Wed, 1 Aug 2018 08:03:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9469528691; Wed, 1 Aug 2018 08:03:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI 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 33325285FD for ; Wed, 1 Aug 2018 08:03:02 +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=uQBRoJ/I/zCpNXgM2UmOhSuEPhkuHyBJKN/WaIbYjDY=; b=PAWyMejQ72SELe5UBSgp7F49Be zs0EZrMQyuap+S68bt8BqZCD+RrWoK6RB4xh9Y7kmfFj9PxE0MSERx1ieXiWwUeCRanAaSZjycPQh GV0cyyVUl49JY2BT5Gitea4cCqNzBwInHCpq1ddDjGwvTaHcr9PITO3jlSjGOLiRRDSBOK9D81yKu 6go6QuuVQBNwzxxR1If8TI8qQwxGr+zacJALAH7sfeOu+Da/2hstQwG2QIkZO7ufsj7JYpkcZxdVC mSHqfQGzTEifdzUgP0XwiQhmPSrnYRZJd2C+EAUmjohK/zQHi2lxjKde085gvHb62I9UGGADYxyd1 0xfPbGrQ==; 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 1fkm5w-0007Lu-GX; Wed, 01 Aug 2018 08:02:56 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm4l-0005kQ-8j for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:02:08 +0000 Received: by mail-pg1-x544.google.com with SMTP id y4-v6so10410700pgp.9 for ; Wed, 01 Aug 2018 01:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oNyPwIsjRhf+ZiEWRkmri6ZF3DwmBYxfrK8HfgRNf3k=; b=ZAryMb/qZx0OKViN+b6ys0hiRqPvP8zCaMkL4ja0xTPB2q0UloM4GrkKFV5wiuNO/P lzmiVk6zOo54gMHgaJfh6aAMPLrzSFlU1lJnzV9iWudQz1+ZVQGcFC61vdHQrXMJUwDG M5DdkZHpJc6iwvCF+yPRD9d5rvirOXYE1lYBY= 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=oNyPwIsjRhf+ZiEWRkmri6ZF3DwmBYxfrK8HfgRNf3k=; b=A5K2HryW7IsFQnIAJy+QOC+IyEp9j0y47gJ5ADDnONUZ5S19TEgAtKYVVK27CdgorF GioAopuTQz8lpnl9jcoDRtbvHsqLhhkmjqso4Ggn17a8XTOjD4WeSWW/F1XqKw1X1ek6 DWxIWzVQ2Guy5do4+aOEb2IoLwE6rjz6GY7Wjvft5Qh6+Z5Kzzbw1RUWuqJ9hWrkcjaJ a+GiZumDtpoTpTtx6o/fx0+JoTV77o4w02H1jl5kbTCXGtK/lKxsRVI3AlZj4cpukvDV dbUlb6RVGbe5FtOedEvSAwPSEB/JasBX42jhujPfweTKCGuisPPhaO5wDWIcRvNGo8ls B8Ug== X-Gm-Message-State: AOUpUlGwM+dxqQDfGqgKihIeAnXaymC8gTBQ6xL2RQyPUHafKtlXLQIj 3xXZ+71nBycIj8XwWN5gJBiJag== X-Google-Smtp-Source: AAOMgpemPQwQ62AsUr1iIbdCW37PmGaLmw6hpdj7waRBisKK4PSZ/gLP/Aa01ZNPz2Qc2EDBSFagXg== X-Received: by 2002:a62:3a5b:: with SMTP id h88-v6mr25710062pfa.61.1533110492352; Wed, 01 Aug 2018 01:01:32 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 70-v6sm12694141pfz.27.2018.08.01.01.01.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:31 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v13 15/16] arm64: kexec_file: add kernel signature verification support Date: Wed, 1 Aug 2018 16:58:19 +0900 Message-Id: <20180801075820.3753-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_010143_866445_EC99BDF1 X-CRM114-Status: GOOD ( 16.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 5988e767526f..fdc4571c142d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -861,6 +861,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 Wed Aug 1 07:58:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10551895 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 ED33C1822 for ; Wed, 1 Aug 2018 08:53:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCC202A00D for ; Wed, 1 Aug 2018 08:53:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF7922B194; Wed, 1 Aug 2018 08:53: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 6ADC42A00D for ; Wed, 1 Aug 2018 08:53: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=GSxWYboBim20iHZWeAsqTnt+M5CEaGDqPpAlb+zUCck=; b=LKPWI1WD9PrzeD7DHxOVUTrBzi qFMBsnhBaV6fpfWd90chb6rRqG8/k7B5zgB812gsMQoEkicOnqp6gGXtZKDmOmtrlfXcrTOVvB0IR fHJKdbtyIBBeeezebwUqQwPUglQdt3C0OUcniGuwmqYX3V7+pvwHXg6tbKlEt4E8LbkT245QZv9yw mAHWzq+c4soBeQ+ggpfcIytOWHsMToW2fLZ0yFwD8xrXIPCElfxQGMTbld5DVb0ecwVZKJWmapBC+ Ihq5X0ctrMHJsAnQuACeBfquN/vM/1LBTuAOTkvhVF0NEo9UzqBf2Zz77cIqrwn0icRvmDL/kt1nv MbPiQSJg==; 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 1fkmsq-0007Mx-DH; Wed, 01 Aug 2018 08:53:28 +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 1fkmsb-00071q-PS for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Aug 2018 08: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=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=w8VIKOiecJBx6UnYS+wdVoLuE 1GYNqvkIJ0TorOThqrRZ2ow1N1uMoI0kTEt5N10YcXC0s8otquKruc664GifSioAuaER4VyZgzdSe YSrrxqEO1VAOsLiGEITlMANfhwQ2JxBdlA8azlIjI6ALGxw3odBuP/MFY0s1mfQKoG99jRnVIdQlc NUXtHNm9F/oY+icFKSMfut3qvEpTYEa3aCiSAI0kCngJPMilPh9ebqJwcChH6PMFtXaBcNLf9VJWI IlFG7Dza9eZdS5TBGOFWVnWW/VfbEgZbe7mTpGntUYosQmGSksycNIejBe+ealPxT8OiJFoiP4lwh 8MKCbCvkg==; Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkm4u-0002V2-K2 for linux-arm-kernel@lists.infradead.org; Wed, 01 Aug 2018 08:01:54 +0000 Received: by mail-pl0-x242.google.com with SMTP id s17-v6so8417406plp.7 for ; Wed, 01 Aug 2018 01:01: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=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=WU9YMzQPUTnoNa5HnOw5eBPp1T5wlr/z+viQAp2LZ9cSIxO8ipv2mPcyWDp4ZgzUnT WyDkooAOOzxEqlB8kLCDABQO2QVOlRMhZB3KkEfJ6khFhMadGcYSqYRkkKUVjBl0VlbF VK+VT5wZGhXDfPxb5LJtU9vUnaUx9zApOz56g= 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=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=LaAcKovr/wPMPAcDnxfZpmX/6EPUoTE+4kJJ81i3RPBaj/YPjaKLVF6Y7WgDSXm+Dm 7WYDr6t/h/05tb2YgqpxAve9vObDJz+IrKlP079sYXI4fXJXHmi5AMBoi6cmyQw048Yd yhfRzQYeqnhtDB/uBFbmxK8JvudYPYKHx5VxvbuWKSMJzVM6F2wyUkIahvF8a+Muah7r qD2F7ePE52x0pihSFY4kvMQgASRaRbwndTbCZpsHvNmSPWJnR2xRb8/77tXhuw7bA7Lp PLkbfp2CHVea/TWaqY35zFgbU3LoztHZsdy83m1KYtK2NG7xgdWbXMJD3sY0LvctABMx rGGQ== X-Gm-Message-State: AOUpUlFFBfmTTorBKgobGnT1SahXRYd8Uollf7VNHxqgwd3JxB7Ptd4p WSiD3D1zcL3VX/6VJoclV6EEwA== X-Google-Smtp-Source: AAOMgpc9REI6aVelkbglbYXZ6kN1MPtdeNrBpOYh1cbBmeNoNQloeUWdSAIYwEuY2aZMgvoRMNx5cg== X-Received: by 2002:a17:902:e005:: with SMTP id ca5-v6mr23681465plb.224.1533110500350; Wed, 01 Aug 2018 01:01:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y3-v6sm46126520pfi.24.2018.08.01.01.01.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:39 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v13 16/16] arm64: kexec_file: add kaslr support Date: Wed, 1 Aug 2018 16:58:20 +0900 Message-Id: <20180801075820.3753-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180801_040152_691395_7F7F42E1 X-CRM114-Status: GOOD ( 23.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org 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 | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index ecaecb122cad..967db9824e3f 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" +#define FDT_PSTR_KASLR_SEED "kaslr-seed" const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_image_ops, @@ -45,6 +47,32 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) return kexec_image_post_load_cleanup_default(image); } +/* crng needs to have been initialized for providing kaslr-seed */ +static int random_ready; + +static void random_ready_notified(struct random_ready_callback *unused) +{ + random_ready = 1; +} + +static struct random_ready_callback random_ready_cb = { + .func = random_ready_notified, +}; + +static __init int init_random_ready_cb(void) +{ + int ret; + + ret = add_random_ready_callback(&random_ready_cb); + if (ret == -EALREADY) + random_ready = 1; + else if (ret) + pr_warn("failed to add a callback for random_ready\n"); + + return 0; +} +late_initcall(init_random_ready_cb) + static int setup_dtb(struct kimage *image, unsigned long initrd_load_addr, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len, @@ -53,6 +81,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 */ @@ -85,6 +114,8 @@ static int setup_dtb(struct kimage *image, /* can be redundant, but trimmed at the end */ buf_size += fdt_prop_len(FDT_PSTR_BOOTARGS, cmdline_len); + buf_size += fdt_prop_len(FDT_PSTR_KASLR_SEED, sizeof(u64)); + buf = vmalloc(buf_size); if (!buf) { ret = -ENOMEM; @@ -164,6 +195,20 @@ static int setup_dtb(struct kimage *image, } } + /* add kaslr-seed */ + fdt_delprop(buf, nodeoffset, FDT_PSTR_KASLR_SEED); + if (random_ready) { + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_KASLR_SEED, + value); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + pr_notice("kaslr-seed won't be fed\n"); + } + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;