From patchwork Thu Nov 15 05:52:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683521 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 2EDD114DB for ; Thu, 15 Nov 2018 05:52:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A6912C13A for ; Thu, 15 Nov 2018 05:52:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EC0F2C13D; Thu, 15 Nov 2018 05:52:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 B7B232C13A for ; Thu, 15 Nov 2018 05:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DrArGUmNojiVoDPw4tk9lSKc8bu8LAXKWmFFL6QzHW0=; b=VjvVHz8rUHsXZp wJqI+L1Vz4MtPjLJx0LdTeQ43KeKJo4/Zn0HUSblKSIKLU+qyU7wU3sD9JGLcRh6vHKzckOQNH1Cg MnlKW+xZ7PVT+K3sOpbzYX42GLFOGdcpSvy+8ZcqMg/HnKMjxYlFimmMlL2gx/xK+uTkJgT0R8Qg3 0Gz48bJ4aZcGajprU4je20xQtZAefYXVxmpjcnp3qkkX+OEXAs537KZDSrDnevRNTj40pZ5Myd6Ak D2RJ8Ex9HPsTDyIzeFyQYcZ8oGKt3uX37vyPQsX5eyYoAuNkZs4x/O0MdUI3wXTVk0AzXNY6vvQeG WXDzk469WOaF9xdcLPaA==; 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 1gNAZz-0005de-Hc; Thu, 15 Nov 2018 05:52:39 +0000 Received: from mail-yw1-xc44.google.com ([2607:f8b0:4864:20::c44]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAZp-0005DF-Gp for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:52:31 +0000 Received: by mail-yw1-xc44.google.com with SMTP id r199so619399ywe.4 for ; Wed, 14 Nov 2018 21:52:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fqOZgrmCseBCFVCglpCnlv6Vd3lKQ1VgNlnEF5YSifw=; b=L0Lh7adaB4/NBz1Jq7eWIVyflBdmNbUxt4AY6CAfqdA8EIpze6HPfem5PTfs/DdIuy nO0Ux+nFEZV3r0qw6u+AayYXEQULmZ5BENYIXIPtRcyWfd4fEEbwi6jvmcgp3HiFs4E4 lmSB8Ghz4NgyoOF6cFUUXgOdAf6u3836RA+ho= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fqOZgrmCseBCFVCglpCnlv6Vd3lKQ1VgNlnEF5YSifw=; b=KfmEO1u4ZWp/5FNLf+SdblrptgN8n3OW+rZQlkUctZxGv4RtsS4TbKBwJiBzHKL5dN Bmyr+XqV1S2by0zsGou7vG9ch7Ygmd/HZcUfQEofEIlLkx89CDg1AGu69bsBQQLztvF9 o05WNyA9md17C7htlvt/h4ueHXb7c4b1wLQLdk6MyKcyplRHlIui5cgMGyD1PlYnIXP6 Y/KAWW/4hNXOLxZLlqh3pq8VKYTbDkdixlocWr6Y3QhDp4lENcigYiYZqdoZc5hupY2t uZv5j1mVbR0fv0l+3OEKV/3ozkOlGKSOpjvzpPpwgx+TM6iwz6POfDRG4Ew7XOcMYlI1 BspQ== X-Gm-Message-State: AGRZ1gLQ4+LA8LI9wTv4HAmhQUmkkSnCheppRasUNN6KgblYEFQO0/Tq TEkQUs2xUJmoZTz0C6rAtogl9w== X-Google-Smtp-Source: AJdET5e9foIDNMtI7yzpRPUxITmnfPNMHjdhpM9Kr8oPLMei4wkjQB5LwSunNm/Dz29XT1XDaeZaYA== X-Received: by 2002:a81:ad57:: with SMTP id l23-v6mr4569256ywk.260.1542261138359; Wed, 14 Nov 2018 21:52:18 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 200-v6sm7892593ywq.97.2018.11.14.21.52.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:17 -0800 (PST) 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 v16 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Thu, 15 Nov 2018 14:52:40 +0900 Message-Id: <20181115055254.2812-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215229_618454_5C7175D4 X-CRM114-Status: GOOD ( 10.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The initial user of this system call number is arm64. Signed-off-by: AKASHI Takahiro Acked-by: Arnd Bergmann --- include/uapi/asm-generic/unistd.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 538546edbfbd..3b7196295fa6 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -738,9 +738,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 Thu Nov 15 05:52:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683525 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 CC84913B5 for ; Thu, 15 Nov 2018 05:53:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B80282C13A for ; Thu, 15 Nov 2018 05:53:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA4302C13D; Thu, 15 Nov 2018 05:53:05 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 497202C13A for ; Thu, 15 Nov 2018 05:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NS+ZCw6fbKekhvvOH4mAY4YQt2roqGuLTvFP5jXrwhE=; b=L7xyhPJzFnxWFr EvrutE2yg4FY1xao6p70BZRw/2EEd/3Wo4fpGxdSf9OPH5ot3mIjrQUNa6Mzke6OIhQqOBx7edCOt 9nT6GSzWw9Uw00qG3IdSzKTTqe77jEXLD35F9KJ7AuL9VvawgK4OukizSvfGDTR6kleWnYp2KVdVT PqSs4xJ2oNkHgZzg4B8KjJ4yQ4Ri+2g3cGng6+2RRT69bV1ovqmiyRsD6iEBEtuEoCEx9DtZAUhBq I3v0bAZqCLCaADNAkdLWusB2OAXBGscVerrrcKs5r/Zof77kfW24E25omZ+smOwly3RA1JxPhmeOk NX434yKfrfbpic/uKfIQ==; 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 1gNAaL-00061P-P2; Thu, 15 Nov 2018 05:53:01 +0000 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAZt-0005Dr-8I for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:52:34 +0000 Received: by mail-yw1-xc43.google.com with SMTP id k6-v6so8235652ywa.11 for ; Wed, 14 Nov 2018 21:52:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h11K0AmVrf07I+hu2nU8xySmOw+R/bUvf0+LW2Q+26k=; b=Byi9Ido6WYyA6ak3oOwmTntFN6ZvPrWq+jnerI2g4TBQeE/AuJ9l5Xgc5LS+yqFM/G cLqhfQmJrhw/n4hQwHh529vaPJWOjbTfW9xLSnpUzBEETZs1YUvjjGk1aQsxuVibqHrb vk2e/tcv6SvR7BsOGP2ME0lvkO0W/eiCtsD3k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h11K0AmVrf07I+hu2nU8xySmOw+R/bUvf0+LW2Q+26k=; b=g69bNf+Xrqa0UtDgZ2sLuF964uIi//AGSZMu/shZdcsigBhB9W7PexKf5Ee8Q0LXBK xRfFefxdqFL3QoWjaXbB5cYRMfUNgDo/O7yVCKCxkrAAZBKz/SWE3jcxU7xPlKKvpKrA y8MLiKllxp7AHxPF9eit0i31WKbniGDym+diXfc8SgGMP1Nc8XLGmfYq7GBDw3G9fYbG X4+HDLtOC9o/CY/WC/A44tRuB05MEyfxFi5kJ9lte+1vTG+upYVEnOoqenTt2BXU7/21 SUmmVCCoUu8GcIA8UmxqBn4gzb/b1YM4YRYP+/O22W0oJ+/abT+YJquqGh09cUHP9yb2 vzqw== X-Gm-Message-State: AGRZ1gIkoWy1EqoC0aPs42WnK/Z4qLrsrahRbfWhyTs1UBLsYtkRV/WN ou6g01XplczfTe4dUdEubUB+UQ== X-Google-Smtp-Source: AJdET5dpmFtPJo2svldfEWKgza+frX4ezfcIY+u4OwC/s2LZ63sRh11skB0kFgfpgIYZ0IEqd8jVLw== X-Received: by 2002:a81:4bc1:: with SMTP id y184mr248875ywa.365.1542261142042; Wed, 14 Nov 2018 21:52:22 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b186-v6sm9764855ywe.27.2018.11.14.21.52.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:21 -0800 (PST) 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 v16 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Thu, 15 Nov 2018 14:52:41 +0900 Message-Id: <20181115055254.2812-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215233_295287_33D812C8 X-CRM114-Status: GOOD ( 12.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Change this function from static to global so that arm64 can implement its own arch_kimage_file_post_load_cleanup() later using kexec_image_post_load_cleanup_default(). Signed-off-by: AKASHI Takahiro Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- include/linux/kexec.h | 1 + kernel/kexec_file.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 9e4e638fb505..49ab758f4d91 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -143,6 +143,7 @@ extern const struct kexec_file_ops * const kexec_file_loaders[]; int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); +int kexec_image_post_load_cleanup_default(struct kimage *image); /** * struct kexec_buf - parameters for finding a place for a buffer in memory diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 35cf0ad29718..9ce6672f4fa3 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -76,7 +76,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 Thu Nov 15 05:52:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683529 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 3A5C014DB for ; Thu, 15 Nov 2018 05:53:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 223B52C13D for ; Thu, 15 Nov 2018 05:53:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11EAD2C140; Thu, 15 Nov 2018 05:53:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 A5F922C13D for ; Thu, 15 Nov 2018 05:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AJARIXuWJnXZa/brs2viiTOI4m/QnmkOeT4SCRH0hOo=; b=hewCZYLhd4/DoD STYs4v4pVDVj0PiFn2LcuEkP5V/cQsUPcqu3KAZqS8ynb/n+tZYkWP85EeDTFqv3Jhd8UqjCopxNq nFrJUFG1IMRGAgU6DX9Tyo5CRDp2laTn+pMU9sHOt7lEaNTTNlT6jYBPWam+ZZuF8YidGXNqK6AyQ X9yOIiS3qLPbxWkK7wd79nkKForkahxR5ZJNR1Fb4eyiFeOMil9rbT2Slm32OWRnNJZ5DwFiRKvdy ckzc8SYsxSjfzwquOX71V0BZUG+MMQ4fQElBmo0i7b9YqT6kGGrScuUL0NJqTRk1eWhzrhyLssXCX gUwJiadZ/YDfXkGIJdoA==; 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 1gNAat-0006Vp-0M; Thu, 15 Nov 2018 05:53:35 +0000 Received: from mail-yb1-xb41.google.com ([2607:f8b0:4864:20::b41]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAZw-0005GF-M9 for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:52:39 +0000 Received: by mail-yb1-xb41.google.com with SMTP id p144-v6so7893548yba.11 for ; Wed, 14 Nov 2018 21:52:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eQVF/NE5LgDyDCoQh0ftmhN/0hZKHUsKcfSHpKIBIX8=; b=SWInm5I83ZSSOs6Oky+TLdEe+XVLwX+bqxuLVQQgTl88XpOcoinPwkYI+tOOOTsO7n am1IVi9JIJYDZ6Ew3fn3vMEfaOurkJV/Lq1FVbuFxPN/BqJUd1dWb5lwbD9suCMIZ42u XVhdIVsHj37uVaAxN1tR5PVJ2GURTvxxka/94= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eQVF/NE5LgDyDCoQh0ftmhN/0hZKHUsKcfSHpKIBIX8=; b=glKFXPZAWstGP+iqEfoCFL4ZLhta+VYicLWjoZhKMMWKdoLps47DpdEi9VEQsrINaB DGlwiRFCTyVBUrtnXFJiOiWi+gYczxAdhVN/OOnXXootyt7T28Srd/s0yMGxZR0p7bMl 3QkTCbIumOaP5pakTuDPXj9TQ0J/e+QcVt7eM7JXvEIBNcQ8qlTaIfhD6VN8lB9sC9c9 tKLmcib3MU9080RqJ6M7SMLtVCdRQxzTkBobx5DBkgXwhliFr/llsnDBENhn120Be3iC 1/dZF4uqSNNo8d53bnqZHFF2/pqM1TLex9z67ia2MLjylQMVGBrWUu4glEyKaLSgY8GH f8Vw== X-Gm-Message-State: AGRZ1gKBArqZrx0hqmObHq0mm0ezzVRV2YMq4Qk1A8aJq6dt/4QOKzqi o1do8WbgFFUV+M+Mrv96MI39Hw== X-Google-Smtp-Source: AJdET5eoU0+q3M0HQPYUhYaHvFr9ychd7XlFTSupZz6V8HiyT8N9roETbqi5SXGMlye4WKAoeWq5pA== X-Received: by 2002:a25:ae92:: with SMTP id b18-v6mr4695234ybj.286.1542261145471; Wed, 14 Nov 2018 21:52:25 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j185-v6sm7067497ywf.4.2018.11.14.21.52.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:25 -0800 (PST) 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 v16 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Thu, 15 Nov 2018 14:52:42 +0900 Message-Id: <20181115055254.2812-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215236_763943_B1BDA11D X-CRM114-Status: GOOD ( 15.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Since s390 already knows where to locate buffers, calling arch_kexec_mem_walk() has no sense. So we can just drop it as kbuf->mem indicates this while all other architectures sets it to 0 initially. This change is a preparatory work for the next patch, where all the variant memory walks, either on system resource or memblock, will be put in one common place so that it will satisfy all the architectures' need. Signed-off-by: AKASHI Takahiro Reviewed-by: Philipp Rudo Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- arch/s390/kernel/machine_kexec_file.c | 10 ---------- include/linux/kexec.h | 8 ++++++++ kernel/kexec_file.c | 4 ++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/s390/kernel/machine_kexec_file.c b/arch/s390/kernel/machine_kexec_file.c index f413f57f8d20..32023b4f9dc0 100644 --- a/arch/s390/kernel/machine_kexec_file.c +++ b/arch/s390/kernel/machine_kexec_file.c @@ -134,16 +134,6 @@ int kexec_file_add_initrd(struct kimage *image, struct s390_load_data *data, return ret; } -/* - * The kernel is loaded to a fixed location. Turn off kexec_locate_mem_hole - * and provide kbuf->mem by hand. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - return 1; -} - int arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section, const Elf_Shdr *relsec, diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 49ab758f4d91..f378cb786f1b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -145,6 +145,14 @@ int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); int kexec_image_post_load_cleanup_default(struct kimage *image); +/* + * If kexec_buf.mem is set to this value, kexec_locate_mem_hole() + * will try to allocate free memory. Arch may overwrite it. + */ +#ifndef KEXEC_BUF_MEM_UNKNOWN +#define KEXEC_BUF_MEM_UNKNOWN 0 +#endif + /** * struct kexec_buf - parameters for finding a place for a buffer in memory * @image: kexec image in which memory to search. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 9ce6672f4fa3..9e6529da12ed 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -532,6 +532,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) { int ret; + /* Arch knows where to place */ + if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) + return 0; + ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; From patchwork Thu Nov 15 05:52:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683535 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 B5AF714DB for ; Thu, 15 Nov 2018 05:54:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0AF52C140 for ; Thu, 15 Nov 2018 05:54:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94FDC2C15A; Thu, 15 Nov 2018 05:54:10 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 CAF922C140 for ; Thu, 15 Nov 2018 05:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JpYj+5GjQULy+nrLdmaq9DtVwo2zErAfZIJlSmdkSZE=; b=bn1RRd4NoMPkTV cO3+PmXi1ml+ZbBZXNOkAX1aEhEsqPvqwoskzWW+h3R4+7A9K4bxhPTPynf14viExo2ufSsY3k8Vy YVOqIpJaAxew0QJ//NgXOWc3lrvuIhPrNbZsw1rRCGkmpO+e4Nc6OEh331IlDLP8fyQLlcWv/ebUj C0WDLFVbgAAWU2TxllEdWuN/ydjo0StmfRU29BUWL7RF778CcpMOZDZw8dktgMiuiSNz/xCyqd+NI OCVVWSXY4P3kSHGyT1IzrCknpyJvxNrjTiUP06/FmwJZKtbDaraVSdSy0KoguUpMYKXT0ywOQMJR2 WXj2uBjJy+D+j9PPQBkQ==; 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 1gNAbP-0006uo-KM; Thu, 15 Nov 2018 05:54:07 +0000 Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAa2-0005RF-AT for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:52:45 +0000 Received: by mail-yb1-xb44.google.com with SMTP id i17-v6so7888978ybp.13 for ; Wed, 14 Nov 2018 21:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vuW0vIeG+fBL43JD346Yj35MDPMUrs8BFpP/g2qIAkI=; b=fmHs7jD24UHXdOuV/RkXNE33quq7FklmXfYHhzdXD54yuqcW05dBiwZbw9bjD6QJi1 04In6CXtz+DS4CTg8ukwS6Y2JN/kyYfarrl7ZKGCclurAduh8t7ooBJ2qMqIrWNyE7wp C9mfdCln8YmApMBPPd6S/bh0RyRPFLGUtIXWk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vuW0vIeG+fBL43JD346Yj35MDPMUrs8BFpP/g2qIAkI=; b=oq8qqRimrzPP2enbgWmWdS7zTAr22mjfmo6LMFyCkO2bSDQwDz9ht845OfMgDfHyyr qgOPKywKizYQqNdNWzjPIujzrfQVscNJsg4aqlGBCNkMl0Wt3Y+Xj/Yeaf57tRaNe7GH NSj9fbCh+bx0cDxIcNM88UP5wj848ZUaXQgfHoSiqyeA741tsqrAXICfgW5ilEMboJA8 tjUT9LpMyXu/l5u8rnYQjzPslRk/y4eMg0U2kfizg4X1FJOtUIPQnj6L/JzPFU6SPhhZ khowzj68/86SgbCcf4Ul4bNt6rpWT4f377L/z80TKKB0kyYRi6tqvZx2Ci/W1XQenlZs pH4Q== X-Gm-Message-State: AGRZ1gK4BPU9N3FksY9BE8fMNMCAotAVwwS9y4WoI1r2Vb+0ZhcjWhBH zyumaHfLasCh8OoG8d/ofilMRg== X-Google-Smtp-Source: AJdET5cSKJSln6HGf2ZJpmsq8nkU9sQMtJCL2cEfX/SXq35ZLGNxWkhAiW8/FTpQTLfMVo/f26hT/g== X-Received: by 2002:a25:b213:: with SMTP id i19-v6mr4461442ybj.414.1542261150950; Wed, 14 Nov 2018 21:52:30 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w70sm603729yww.76.2018.11.14.21.52.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:30 -0800 (PST) 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 v16 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Thu, 15 Nov 2018 14:52:43 +0900 Message-Id: <20181115055254.2812-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215242_555520_72D01F7F X-CRM114-Status: GOOD ( 19.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, "Eric W. Biederman" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Memblock list is another source for usable system memory layout. So move powerpc's arch_kexec_walk_mem() to common code so that other memblock-based architectures, particularly arm64, can also utilise it. A moved function is now renamed to kexec_walk_memblock() and integrated into kexec_locate_mem_hole(), which will now be usable for all architectures with no need for overriding arch_kexec_walk_mem(). With this change, arch_kexec_walk_mem() need no longer be a weak function, and was now renamed to kexec_walk_resources(). Since powerpc doesn't support kdump in its kexec_file_load(), the current kexec_walk_memblock() won't work for kdump either in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 ------------------ include/linux/kexec.h | 2 - kernel/kexec_file.c | 61 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 60 deletions(-) diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index c77e95e9b384..0d20c7ad40fa 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, return kexec_image_probe_default(image, buf, buf_len); } -/** - * arch_kexec_walk_mem - call func(data) for each unreserved memory block - * @kbuf: Context info for the search. Also passed to @func. - * @func: Function to call for each memory block. - * - * This function is used by kexec_add_buffer and kexec_locate_mem_hole - * to find unreserved memory to load kexec segments into. - * - * Return: The memory walk will stop when func returns a non-zero value - * and that value will be returned. If all free regions are visited without - * func returning non-zero, then zero will be returned. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - int ret = 0; - u64 i; - phys_addr_t mstart, mend; - struct resource res = { }; - - if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, - &mstart, &mend, NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } - - return ret; -} - /** * setup_purgatory - initialize the purgatory's global variables * @image: kexec image. diff --git a/include/linux/kexec.h b/include/linux/kexec.h index f378cb786f1b..d58d1f2fab10 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -192,8 +192,6 @@ int __weak arch_kexec_apply_relocations(struct purgatory_info *pi, const Elf_Shdr *relsec, const Elf_Shdr *symtab); -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 9e6529da12ed..d03195a8cb6e 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -499,8 +500,57 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#else +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; +} +#endif + /** - * arch_kexec_walk_mem - call func(data) on free memory regions + * kexec_walk_resources - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. * @func: Function to call for each memory region. * @@ -508,8 +558,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, @@ -536,7 +586,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) return 0; - ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); + if (IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + ret = kexec_walk_resources(kbuf, locate_mem_hole_callback); + else + ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Thu Nov 15 05:52:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683537 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 CC66114DB for ; Thu, 15 Nov 2018 05:54:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B819E2C140 for ; Thu, 15 Nov 2018 05:54:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB7982C15A; Thu, 15 Nov 2018 05:54:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 5E4BE2C140 for ; Thu, 15 Nov 2018 05:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VY+wmPVOvv4HVwd1HlYqfdnH046F+0+dYMGmMAqQ58I=; b=DcdQDzQij4NQIT 2xo9ZovZBiUmA957p2pg8WG7w92UyowXYNHFt6TWgKhsQFeqAdo/jczRrNBLfWYeesng8y1qEeVtQ 7txVLZhhCTMvGnpz3mLMCA7hscZu72QylFsC7xSY7kkt6Vtju+0ESL9QG0QBLsDjQo04Kv+rjuoIH ax8Xd9JVaiyub74GZS3d0ieRdt3w9FN+1OSjopezWEiZErONc5vw5F6S8VXXmE8xEdzGSE24/EIbe w4zHUMwMjDn0WOrdO4Dp3D9EJy5+3+CDPH++jEy5lGz7mCgHfT8rg5Ft+EUcO33UjrYo/E91ZxkP1 l4a5qg97suKd2bVOx9RA==; 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 1gNAba-00077F-RD; Thu, 15 Nov 2018 05:54:18 +0000 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAa5-0005Xc-Qy for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:52:47 +0000 Received: by mail-yb1-xb43.google.com with SMTP id g9-v6so7911031ybh.7 for ; Wed, 14 Nov 2018 21:52:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q/fq5bZ27j9TjpABnmRVQDUsaoFNf4lBmEvm436b7+U=; b=NlwwTDBlmA0fPIJo73KUlSBR/mJEba1O118YChkrG+s1/ZraNj0Y01Tr0TFVBwvcqE b3VP3vfW5vtlKY/Yaut01gBNk/g90XX5pObDWWY1scgLt7FWnLNwf0k/f/ZJAMsfodDT 75tdAFCP5GXJcGbY8269qap+A6eZpP3OQmtvA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q/fq5bZ27j9TjpABnmRVQDUsaoFNf4lBmEvm436b7+U=; b=V5+7+Wp9Ww3AApDE7P1vhunmkEA8osxvF/K5AXN/KPk7AZ8q6+Q5ViAYPjsqVRon5u Y+YDI8AqFBCqYWTtL84pzI6Gn4frUFBYneJOfCEgIcIfH3GbXlkBlwkrMzYptyDs4mYY cvHxqn5e3pbfw4fu4z44OcV2JGrFz/GcwjBDwbJoHCidhakOOFQCQ0OMlHeaIzmVUjjx 8R45f2DEro1Cs+cwZaiNxcKeqsDfqyLoQjvnH33MG82/LTNbB3t3xATWWJ+Vv/HYbno3 KzNtguK9JaZDZOeTr6v3GgVUQHcPbZkZj2WwaYdL3JwmdR8+Th5vz0IQLmHoDjVTuHs+ ftKw== X-Gm-Message-State: AGRZ1gK8OpQai5goia4/sJ3bjQ8WMVxH0XrLLCqJs67iuAR0vzNFKv3r 5RA85WsHw2g2Vb1yyLaUkgVQGw== X-Google-Smtp-Source: AJdET5dV1cECJynsv29Nko5CWSDppNLoqAh4iDzCukPadApvjHVw3IyQVZdv0pPSnKHwEVXokEeW1A== X-Received: by 2002:a25:5983:: with SMTP id n125-v6mr4130285ybb.209.1542261154572; Wed, 14 Nov 2018 21:52:34 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 207-v6sm7416843ywo.87.2018.11.14.21.52.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:33 -0800 (PST) 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 v16 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Thu, 15 Nov 2018 14:52:44 +0900 Message-Id: <20181115055254.2812-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215245_882515_C81C4D79 X-CRM114-Status: GOOD ( 12.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 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 Acked-by: 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 d03195a8cb6e..f1d0e00a3971 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -515,8 +515,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 @@ -530,8 +533,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 Thu Nov 15 05:52:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683539 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 E95DF14D6 for ; Thu, 15 Nov 2018 05:54:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5CE92C15A for ; Thu, 15 Nov 2018 05:54:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9F3B2C248; Thu, 15 Nov 2018 05:54: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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 5AF602C15A for ; Thu, 15 Nov 2018 05:54: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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mUviTFlofVu6vcNhIyC3QCK+8+j2YUf04NLVz/3C1yM=; b=aLGLEeciD+6WTB FLUfRpl9qPa/HRa2pwiXOTtHc1d+Nd3I18Vm+nYdESwfPJ23CUsZi86vST3ThRn1WR0hLdLH0e/AC xHkeE8XLwjqGzSc3TVGM16S4b0rwA3bW0O/DKtHOOvL9aOMVt2PqyCkIgL1hjbYiT1Fn3SPVRBzI4 EZ3Z04KR3SEuU9z7xxwd+A+Y6WVJWQ6HoK7MTFEnz1eYZGDs5o3feJ/ypb0hUeN4CPM2JjkCe+hoo mVB+N0UP/LTqUExLkx3k6yx6L595CkD+aE2bzqGGn4SqgjTwlE1vByBKyPV2rCuSvRQHUlzbUG5Q9 RXNbGAzqJ7aUsnSL94JQ==; 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 1gNAbv-0007SJ-0i; Thu, 15 Nov 2018 05:54:39 +0000 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAa9-0005cd-1h for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:52:51 +0000 Received: by mail-yw1-xc43.google.com with SMTP id k6-v6so8235803ywa.11 for ; Wed, 14 Nov 2018 21:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mrPWZ4GdwOXyyhtosApIY//VWuTOROBlwQRdZLFfLfw=; b=HiV+WPPxY/gSkZ6gC+DNCc9Y2vBWfNVgOPT3BWdpSNF+ZsRnS37STM1PxhFeWOxJk7 cFOvcEWifXIokZViFT+vbL4+egWfA/TxC+vIG0ft1dHcRhRNLy48J8+rUXOumtlY1ryE IJDckuWhvjAIuWei/B3sc/6i3+b0++1ZR75SQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mrPWZ4GdwOXyyhtosApIY//VWuTOROBlwQRdZLFfLfw=; b=brLAq48Lf8cG21znTmoC7IbswbbffKBJBqZaHSfOOqmTUk/TqUKO9//lOtFXKcCggL 0DOohDdpcrdTrD08a3ABHucCTStzH6mbMOu/BFOn3EovccGpQDpD8s0QBNWQ4iwkjqCc b4lK8K4csrqQl0T/T4lIvq7KzCRM2wlCiInQ5Rb77h4XfkiehpKLOL+byZwVQ2O1RNXg ZwGfyTSYFeG/LZC1zmxQthFT5/UNQIw/gDpxi4RLOIenrjHNGdVKAmxQzrQxFZ2Wv2+E 8DyBgHOfUGjEMNJP+kdUEMGFmLr2mFh2P+mlQ0c7SKGbVI3CpqZAW9BGuZyqXg+fRean /mxg== X-Gm-Message-State: AGRZ1gJCb+IDZLz2ALs5fDfJxty8yvGWf0yEdWhN4HfOYmoTfMqgWWKa 9N9S/ZDasrhLu5Oq+lzRLXcIfw== X-Google-Smtp-Source: AJdET5fkMvsm2DHLjgTVbC8xwZoGqVoWAD7HWYAuRL/sUOtxs2GKhrvUm8Sfip4SGiWaYCL36lo1+A== X-Received: by 2002:a81:2f89:: with SMTP id v131-v6mr4450717ywv.104.1542261157829; Wed, 14 Nov 2018 21:52:37 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o131-v6sm6399857ywb.107.2018.11.14.21.52.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:37 -0800 (PST) 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 v16 06/16] lib: fdt: add a helper function for handling memory range property Date: Thu, 15 Nov 2018 14:52:45 +0900 Message-Id: <20181115055254.2812-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215249_093097_E5DF5BF1 X-CRM114-Status: GOOD ( 16.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: devicetree@vger.kernel.org, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , Rob Herring , james.morse@arm.com, Frank Rowand , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Added function, fdt_setprop_reg(), will be used later to handle kexec-specific property in arm64's kexec_file implementation. It will possibly be merged into libfdt in the future. Signed-off-by: AKASHI Takahiro Cc: Rob Herring Cc: Frank Rowand Cc: devicetree@vger.kernel.org --- include/linux/libfdt.h | 26 ++++++++++++++++++++ lib/Makefile | 2 +- lib/fdt_addresses.c | 56 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 lib/fdt_addresses.c diff --git a/include/linux/libfdt.h b/include/linux/libfdt.h index 90ed4ebfa692..47c4dc9e135c 100644 --- a/include/linux/libfdt.h +++ b/include/linux/libfdt.h @@ -5,4 +5,30 @@ #include #include "../../scripts/dtc/libfdt/libfdt.h" +/** + * fdt_setprop_reg - add/set a memory region property + * @fdt: pointer to the device tree blob + * @nodeoffset: offset of the node to add a property at + * @name: name of property + * @addr: physical start address + * @size: size of region + * + * returns: + * 0, on success + * -FDT_ERR_BADLAYOUT, + * -FDT_ERR_BADMAGIC, + * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid + * #address-cells property + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag + * -FDT_ERR_BADSTATE, + * -FDT_ERR_BADSTRUCTURE, + * -FDT_ERR_BADVERSION, + * -FDT_ERR_BADVALUE, addr or size doesn't fit to respective cells size + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to + * contain a new property + * -FDT_ERR_TRUNCATED, standard meanings + */ +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size); + #endif /* _INCLUDE_LIBFDT_H_ */ diff --git a/lib/Makefile b/lib/Makefile index db06d1237898..2a96cb05e15d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -205,7 +205,7 @@ KASAN_SANITIZE_stackdepot.o := n KCOV_INSTRUMENT_stackdepot.o := n libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \ - fdt_empty_tree.o + fdt_empty_tree.o fdt_addresses.o $(foreach file, $(libfdt_files), \ $(eval CFLAGS_$(file) = -I$(src)/../scripts/dtc/libfdt)) lib-$(CONFIG_LIBFDT) += $(libfdt_files) diff --git a/lib/fdt_addresses.c b/lib/fdt_addresses.c new file mode 100644 index 000000000000..97ddd5a5cc10 --- /dev/null +++ b/lib/fdt_addresses.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "../scripts/dtc/libfdt/fdt_addresses.c" + +/* + * helper functions for arm64 kexec + * Those functions may be merged into libfdt in the future. + */ + +/* This function assumes that cells is 1 or 2 */ +static void cpu64_to_fdt_cells(void *buf, u64 val64, int cells) +{ + __be32 val32; + + while (cells) { + val32 = cpu_to_fdt32(val64 >> (32 * (--cells))); + memcpy(buf, &val32, sizeof(val32)); + buf += sizeof(val32); + } +} + +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size) +{ + int addr_cells, size_cells; + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + addr_cells = fdt_address_cells(fdt, 0); + if (addr_cells < 0) + return addr_cells; + size_cells = fdt_size_cells(fdt, 0); + if (size_cells < 0) + return size_cells; + + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((addr_cells == 1) && ((addr > U32_MAX) || + ((addr + size) > U32_MAX))) + return -FDT_ERR_BADVALUE; + + if ((size_cells == 1) && (size > U32_MAX)) + return -FDT_ERR_BADVALUE; + + buf_size = (addr_cells + size_cells) * sizeof(u32); + prop = buf; + + cpu64_to_fdt_cells(prop, addr, addr_cells); + prop += addr_cells * sizeof(u32); + + cpu64_to_fdt_cells(prop, size, size_cells); + + return fdt_setprop(fdt, nodeoffset, name, buf, buf_size); +} From patchwork Thu Nov 15 05:52:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683545 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 1FE7814D6 for ; Thu, 15 Nov 2018 05:55:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 052CA2C158 for ; Thu, 15 Nov 2018 05:55:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E804F2C140; Thu, 15 Nov 2018 05:55:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 253382C140 for ; Thu, 15 Nov 2018 05:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jqn4aA+NZKiKzZtlC9F3EIGxSGzxE4jG3BQ5kz2llss=; b=TkMF4/mWnWJC3S YB23qNeeUk+Du7G+rIgEjVkSekAFxtnkQHXIKazg5E4aULKL0p9sL0QhHYd1B5YrMX7JM6206FWT8 h+jCmOaAPEOiu8FP6RIBvaTuKCd1AwVMUZrB9ibWWFm36cV8F691QK3iRpxBA1PeTFRKVLj3Mu+J9 33q6yW+RJdw9TFGoQ8NWknQEh4FCQJzvGKjLG8Cb3Jysb0oGHRU73HIg+yYl7sebQlAIbTpSD91gX 3HIFEk24JDgz7YOQMyliaEreGjNUvZYiGrR/qL2Z2pog4x+TnM8TCuxC/tkQVwlkQZmKyynaJsnzc jS2z7JzxOWwhSPDuXAgA==; 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 1gNAcD-0007lJ-LL; Thu, 15 Nov 2018 05:54:57 +0000 Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAaD-0005hc-PF for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:52:55 +0000 Received: by mail-yb1-xb44.google.com with SMTP id h187-v6so7902838ybg.10 for ; Wed, 14 Nov 2018 21:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BhVPs0/6RkCK6rd2OYDrSNPF0bSzTb9H/aaLYLX1Jv0=; b=WxwDcLSFuqY21hY7SAVmE9m6wvTPTpkujhMeYjGRCOsM8vBVn7VNbQhMOv/QDzYTtl F+Bwmu9H+GHc6kw9TrduFZrE2xvJSovmSS6M5wRhMgARpNzJ63q4ktuq2QT2RCVJfa9b q/RXBcooI4IvUtNJAV0WNKl7o9lo4kDsyCQSE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BhVPs0/6RkCK6rd2OYDrSNPF0bSzTb9H/aaLYLX1Jv0=; b=DhiUvzYs/Ekl7yYjYQYTVhxBB7PuF89xkgvJh47XoV+yYHtwA9/f61gzD2HM40dvu+ MWf0fdrIwaJwtTrxoi0OAJi+1TzejldaP7ZfMQoawJg3ok1/nHCmU/f8g5YqIUJoChWC MNs1783oXgXi1LxHH9yp7xSm4itqFKZN0nwuM+pxjLpIbxmH61/r8McKNpxATm+DWNlm pD9kDPDF6atsfrQO7tZyTUNhsKxOKvtKN3LdZNs7MFrdUjIgqW95mT5Xnx0AmmmDRQil SOAgJ6Dq/JhlxACvYnh9ggCp3khczxS7kId/MF0DQoPXzFYh1m1VxWKMNfn7PHOY4uku 7kbg== X-Gm-Message-State: AGRZ1gKVTQM4EwoyvmDtg56UBpVeSPm6KJjz/KMKAq7gmj9twn66rgfG ngRM922eB7h+eHa0MtYLfoGj7A== X-Google-Smtp-Source: AJdET5deiDqOxZe4N/79xPi6cOjAlTm6UK+usVXvOGy9hhV6IwkpdH+U1g5XKUAcgLVN2n2bt4iyKg== X-Received: by 2002:a25:cf04:: with SMTP id f4-v6mr4496008ybg.261.1542261161782; Wed, 14 Nov 2018 21:52:41 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 1-v6sm6680791ywm.3.2018.11.14.21.52.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:41 -0800 (PST) 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 v16 07/16] arm64: add image head flag definitions Date: Thu, 15 Nov 2018 14:52:46 +0900 Message-Id: <20181115055254.2812-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215253_865957_E084E74E X-CRM114-Status: GOOD ( 17.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Those image head's flags will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Acked-by: James Morse --- arch/arm64/include/asm/image.h | 59 ++++++++++++++++++++++++++++++++++ arch/arm64/kernel/head.S | 3 +- arch/arm64/kernel/image.h | 21 +++++++----- 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 arch/arm64/include/asm/image.h diff --git a/arch/arm64/include/asm/image.h b/arch/arm64/include/asm/image.h new file mode 100644 index 000000000000..e2c27a2278e9 --- /dev/null +++ b/arch/arm64/include/asm/image.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_IMAGE_H +#define __ASM_IMAGE_H + +#define ARM64_IMAGE_MAGIC "ARM\x64" + +#define ARM64_IMAGE_FLAG_BE_SHIFT 0 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT (ARM64_IMAGE_FLAG_BE_SHIFT + 1) +#define ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT \ + (ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT + 2) +#define ARM64_IMAGE_FLAG_BE_MASK 0x1 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_MASK 0x3 +#define ARM64_IMAGE_FLAG_PHYS_BASE_MASK 0x1 + +#define ARM64_IMAGE_FLAG_LE 0 +#define ARM64_IMAGE_FLAG_BE 1 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_4K 1 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_16K 2 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_64K 3 +#define ARM64_IMAGE_FLAG_PHYS_BASE 1 + +#ifndef __ASSEMBLY__ + +#define arm64_image_flag_field(flags, field) \ + (((flags) >> field##_SHIFT) & field##_MASK) + +/* + * struct arm64_image_header - arm64 kernel image header + * See Documentation/arm64/booting.txt for details + * + * @code0: Executable code, or + * @mz_header alternatively used for part of MZ header + * @code1: Executable code + * @text_offset: Image load offset + * @image_size: Effective Image size + * @flags: kernel flags + * @reserved: reserved + * @magic: Magic number + * @reserved5: reserved, or + * @pe_header: alternatively used for PE COFF offset + */ + +struct arm64_image_header { + __le32 code0; + __le32 code1; + __le64 text_offset; + __le64 image_size; + __le64 flags; + __le64 res2; + __le64 res3; + __le64 res4; + __le32 magic; + __le32 res5; +}; + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_IMAGE_H */ diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 4471f570a295..4d0b78c95c34 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -91,7 +92,7 @@ _head: .quad 0 // reserved .quad 0 // reserved .quad 0 // reserved - .ascii "ARM\x64" // Magic number + .ascii ARM64_IMAGE_MAGIC // Magic number #ifdef CONFIG_EFI .long pe_header - _head // Offset to the PE header. diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h index a820ed07fb80..d843f9cbcd92 100644 --- a/arch/arm64/kernel/image.h +++ b/arch/arm64/kernel/image.h @@ -15,13 +15,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef __ASM_IMAGE_H -#define __ASM_IMAGE_H +#ifndef __ARM64_KERNEL_IMAGE_H +#define __ARM64_KERNEL_IMAGE_H #ifndef LINKER_SCRIPT #error This file should only be included in vmlinux.lds.S #endif +#include + /* * There aren't any ELF relocations we can use to endian-swap values known only * at link time (e.g. the subtraction of two symbol addresses), so we must get @@ -47,19 +49,22 @@ sym##_lo32 = DATA_LE32((data) & 0xffffffff); \ sym##_hi32 = DATA_LE32((data) >> 32) +#define __HEAD_FLAG(field) (__HEAD_FLAG_##field << \ + ARM64_IMAGE_FLAG_##field##_SHIFT) + #ifdef CONFIG_CPU_BIG_ENDIAN -#define __HEAD_FLAG_BE 1 +#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_BE #else -#define __HEAD_FLAG_BE 0 +#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_LE #endif #define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2) #define __HEAD_FLAG_PHYS_BASE 1 -#define __HEAD_FLAGS ((__HEAD_FLAG_BE << 0) | \ - (__HEAD_FLAG_PAGE_SIZE << 1) | \ - (__HEAD_FLAG_PHYS_BASE << 3)) +#define __HEAD_FLAGS (__HEAD_FLAG(BE) | \ + __HEAD_FLAG(PAGE_SIZE) | \ + __HEAD_FLAG(PHYS_BASE)) /* * These will output as part of the Image header, which should be little-endian @@ -119,4 +124,4 @@ __efistub_screen_info = KALLSYMS_HIDE(screen_info); #endif -#endif /* __ASM_IMAGE_H */ +#endif /* __ARM64_KERNEL_IMAGE_H */ From patchwork Thu Nov 15 05:52:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683549 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 CBC081747 for ; Thu, 15 Nov 2018 05:55:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B76372C140 for ; Thu, 15 Nov 2018 05:55:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAE4E2C15A; Thu, 15 Nov 2018 05:55:29 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 29FB12C140 for ; Thu, 15 Nov 2018 05:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=90eRkzDBjUxR9v80XKn6ERTLo6vaifKGEa2r3REfrbU=; b=q/USzYkjUOZVp5 ZKY9YdFkaROlIZSin3M34GHGyFGUjljId/yMUvLplt5qBDFN4LgHDh4i8EkEtpoMQhOsZBrcSmun/ EkCR8iTQBK8DsMedbwSYtkx3VOnM1U+BO7HhcaF9loiRdQD6ZHUFh9vJ4nKTRSIXTFm/m9qkqzh16 rVAIYfMqPu3q0e2Lsunu6yImAKW1AKoiwwsiQEfEZWs+CpjCAx/7/MV9YxDxGQzTvEabgTkltguxc hyJXVFl0kLpiVBZM9kSr6yUbPJcgFNSJbH9KsMQNfHaBGE/+Gaye5h7xURoQnXKkhHQqqBzxwRWvv 5uJ8fPx5vR1gcwuC6t3Q==; 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 1gNAcg-0000x3-Hz; Thu, 15 Nov 2018 05:55:26 +0000 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAai-0006CO-D8 for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:30 +0000 Received: by mail-yw1-xc43.google.com with SMTP id p18-v6so8222570ywg.12 for ; Wed, 14 Nov 2018 21:53:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o5y8l0NsFtoWbp90IzL9nHnwXBQanitGUE7PDY2nFw0=; b=EtBHn+kvNnc+4EN2r0hbJOtGY9b+zYbzmZmiED+K8NRA7cYk1XfWnhksshiqQhgAEN ix8GpkWl+fDniCZKDfw1vzsSg0b78KRVJcHl2pWwVi1/5LbchSUTp73Er1LUijszQhf5 102zObBAKbKK1ewHXbJJ6C5kj4FiqqC/04haw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o5y8l0NsFtoWbp90IzL9nHnwXBQanitGUE7PDY2nFw0=; b=h/OhR7PFNdD5qZhzFLrPi3i8NeQX9iplgLif2imJru4idH2+HGrrD8VtwkPoGwPYYe wJzW4kwiwm1nVvta3IECHIdNIolPUeQHzKasr1u9N68ONG12LTjt3DWrGDW2L2Sax37b 2SZNIr77OM9ACuRIqzLfIwF6qarIDUv2YCCzkjU16XMneCqufNr3KJ5L7UKw6Y+bNaWL Adw8WitubFePaQc/EMCZSPeH541OEgFuiZGU/yAfNXtKp8NIzPi7s/Bo72oI11ZwS0RJ uGORjaY7YwyhNaFvj/BwAXXFdRZrLEsXM5rQ5OoFUnKJKLgaVG5BR9KNc9HLzdbRpQAy sa2Q== X-Gm-Message-State: AGRZ1gJocZ5/HTf9u8kM6iZ7Jl5kZDV5U8ab58Ucg6ZFtBZ1xI0VpUHC eWsOGooFylAugFOEWNTbX2cgkg== X-Google-Smtp-Source: AJdET5cLVSe3DdE5jgpOWdPQDybq6OD5ogbCr+lRGJR4mlAHIRvUQ84xBa3h/jl5HLpW8gIQeHTEbQ== X-Received: by 2002:a81:5089:: with SMTP id e131mr1242482ywb.392.1542261193064; Wed, 14 Nov 2018 21:53:13 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 207-v6sm7417310ywo.87.2018.11.14.21.53.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:12 -0800 (PST) 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 v16 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Thu, 15 Nov 2018 14:52:47 +0900 Message-Id: <20181115055254.2812-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215324_475918_F92C8134 X-CRM114-Status: GOOD ( 10.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Those helper functions for MMFR0 register will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/cpufeature.h | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 7e2ec64aa414..ef118d819fe8 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 Thu Nov 15 05:52:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683551 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 7789914D6 for ; Thu, 15 Nov 2018 05:55:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61EAD2C140 for ; Thu, 15 Nov 2018 05:55:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5550E2C15A; Thu, 15 Nov 2018 05:55:59 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 CD7F42C140 for ; Thu, 15 Nov 2018 05:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R9Awwh/WsbEet+9nG1UtGVwQ8wLSDi6Zsd+KnajvKlk=; b=TMaqjEmqlA9ymX ldfuIzyJGKMvhVTKwrYAuTGG4uEeSltRRN5GauyXrcBK9yidpjhQOGjZaTtMK8eHuWz9qNAqApI11 cuaFMzJUOMSNZdhxn2DUQKFQGaEWcnyhfPT9+X9K4JpcqfAhehwJJponIR1OPP5q0Ci1pLrbazyCv +p+Hblf2tK2L226nMNzgRzXLe3v0gXh3oQQk5KrfKwwkG+Lz64z3ZZ7VGHN2a6vBZBLT2YAqKwTjW aVHhJZnQuwg/3XrHkl44FTEivUzRAAnTCLg5Y6upbqRy7e8TRzc+wGLT4SQAKyFqwESv47jXtCb2O kNRZ4CfwpXMwqyXHLkFQ==; 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 1gNAd7-0001L0-Hu; Thu, 15 Nov 2018 05:55:53 +0000 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAam-0006GJ-RD for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:35 +0000 Received: by mail-yb1-xb43.google.com with SMTP id h187-v6so7903251ybg.10 for ; Wed, 14 Nov 2018 21:53:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v/2g1t2ZiuSybJx6NO3mxBVk7FXFeZVpACxhmjpzZl4=; b=WRM172Hvt4U1KKJWpGr+jhsdTHlND6n0dqnf7rnB7KR/ez937GBqOmCQCx1s21rU0p ujsZeGL5rIRXhbwM/XGgrEUm8q1RE20jG14eR764S9DPpUM1XDNxeOD3x8y8GSTl1UVZ 1rt2/niMdKhX5PvrZYLdimEpAHH7VSWUy5rNM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v/2g1t2ZiuSybJx6NO3mxBVk7FXFeZVpACxhmjpzZl4=; b=JPzsAJIL5oR7iCh/zHa8odzp4Ih62wlrb3OiPx5l1DJS1NkhQm6vTouQRjo9ZvaYtP LhEE+dyCTHGt3XABpXmLZwtxfwGd+dQg9B0jwUBzF8bxxY7OkKKPktNtemE39YiPjbM7 SXYycHGlxVpRNMOJf4B94+FdLjYiulBwm5BoTomEraKgByMJSZFPFjtGik9n8Zg6l7If xLDREqEh/ai8JDTqrE3c0ZV/16J9SN71P1+oAmT7uJOPwgNzCJdYRP1i+lquPpb8u3is baXUzb9JnzRPSORXDB3q3se1seC3Cgtlglf1b0u0pOcBxozlM7Gac59vPySHTeaBGazR pv+A== X-Gm-Message-State: AGRZ1gJe3D6+EWehZhJTn5utcWYoe19n+GqbTJehgCEJ8x2RPFPSqIiJ PkQgJ4jlQ3yYlpNQ/04m6yQ85A== X-Google-Smtp-Source: AJdET5eL4UvzIiUqLTSwJlF/faDVYgAhj41qDVfZC9x7FDJJIszpXTG+cTHyextEIIGCfJdne+plig== X-Received: by 2002:a25:2d16:: with SMTP id t22-v6mr4345342ybt.352.1542261197591; Wed, 14 Nov 2018 21:53:17 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r5-v6sm8102379ywr.80.2018.11.14.21.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:17 -0800 (PST) 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 v16 09/16] arm64: enable KEXEC_FILE config Date: Thu, 15 Nov 2018 14:52:48 +0900 Message-Id: <20181115055254.2812-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215328_914772_9D0847FC X-CRM114-Status: GOOD ( 14.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 787d7850e064..93dc4d36d6db 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -858,6 +858,15 @@ config KEXEC but it is independent of the system firmware. And like a reboot you can start any kernel with it, not just Linux. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + help + This is new version of kexec system call. This system call is + file based and takes file descriptors as system call argument + for kernel and initramfs as opposed to list of segments as + accepted by previous system call. + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 4c8b13bede80..030a39bff117 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -49,8 +49,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..c38a8048ed00 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; From patchwork Thu Nov 15 05:52:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683553 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 2949C14D6 for ; Thu, 15 Nov 2018 05:56:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1358D2C20F for ; Thu, 15 Nov 2018 05:56:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 033582C24F; Thu, 15 Nov 2018 05:56:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 B67442C20F for ; Thu, 15 Nov 2018 05:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yp+ml3/c+zjBOaVTOPvR/2ZlIQsMh0uyeRkBg2U8eGE=; b=ZXdBBoqQIHbz9j Lhb7QHeRHjU6bhxINB+XKV3n/VeUDQ+iZKo2g+Eav5Sh4DyDrcuLvtkup7HfS6yHE+KCInAt44cRd wdh66LY79Z/xzKqIShLCLnttw7m0/m6o9LDsrgPytRhjL8pvj3JFyINzMkOfJTHU3pBiCQlRiXfVu s4WAlU32WWbCIYF6HHG7EDr3l+qFBCtKY4m7/6vIMjc8pP5i5KUqwmhmBsBXdVdFGzMIVgdtx2Rdf cYrpse42SSFKdUz58eGMcz2iMpYHhbxn1RxCpjO/3ahouDOBfX89RUxFl2st70FlcheWP6kjTeN6o IG7GdP+feLD9I4kkITMQ==; 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 1gNAdT-0001dI-OO; Thu, 15 Nov 2018 05:56:15 +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 1gNAax-0006Ye-0o for linux-arm-kernel@bombadil.infradead.org; Thu, 15 Nov 2018 05:53:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type: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=DVw/N+4o4xfdKNT3rQ+yr/g2LmbUltluLPP7xa2j7CY=; b=I5uVsinZIoe+DagorS6IzJ/LfJ LCUKfafgTzlnMnZYL+ySiM9W6sov+i2FDtF/5qo5Ap3gghxZIbr+9Rm0kzNxI7RHItJ1b6XhwEmq3 MuAUpvjZ2EFTLVlejNkzw3B6Uv+vg1jZXY0SonFNTS3ipdWyd6UwKvtycDZDVi+moKB+F3dslqwiJ BKD34iJ+Yg9RnWXuGs23Bfx9PNOjJv2BH8UqWw8SKzVZzhsMEp0SAzdlwqoMHTf/hckyuEnUDopdG stESxv/d/9W/pVTcBb5Gt8Jm/k83CqcmOckA4M/f53eFQzbXkfj07mBZayQ0H9VQJz3sgtpY4Er75 38djsLDw==; Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAat-0006qB-Pn for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:37 +0000 Received: by mail-yb1-xb44.google.com with SMTP id p144-v6so7894126yba.11 for ; Wed, 14 Nov 2018 21:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DVw/N+4o4xfdKNT3rQ+yr/g2LmbUltluLPP7xa2j7CY=; b=GsW9jmBCepRRuemOaWg1s/fdiX69XAbbte5iR4Y6/rfI01QRT7mbkPfb8OzkOfxK0w y/5MfoK7vDnE5RpI4HRZ9ID6g9bA1Nq0uZ9++cl0L+B8nOhsR79UAiYVRUMSsDy5qpQs XeUoRbfCBofNBT82JdJZ+vVT/FzlsAZxelXVc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DVw/N+4o4xfdKNT3rQ+yr/g2LmbUltluLPP7xa2j7CY=; b=qlxNk6fgQ7nrlk9cAJYS5H+iy8sPi3V4gTxBrfWYuMT5BqMgUy75hqQ10enkio1vGx ywq98slvQhOH9DT4SMJaP4s4xkV85sX3NgveoK1coXKTXmk0fVx0Sz1rkZ2+NgAAA1EH 73boUv/jplf2di8kKLdJqfdMmj/UP0FHoL2qSGpeOtBgwnj2ZtNCuk8ao6iTzOo6HCB7 YjEdb3Gbf8EWDjC33/qjXAE0jFzCVnc11iG749gyG0A+3pOjl0Fe0TPJBDy7UYWEwZPQ ZvfhCqPGFjLUJ4lKa0lC0CHaCRQvcDa2hoIh5l+SdeUodPnou+1ZJHAkNCcTDo1os7+C HnhA== X-Gm-Message-State: AGRZ1gIwTNSxd3vNBEavrg6Z2RSdZXq3FoEaKvdFf5zfGoF9/ac1UvVH HYd2oWXzJfKTB5venj4pSnOQ4Q== X-Google-Smtp-Source: AJdET5d+kFXnkqMko+jgItDYVJf5BJsTF/ydXwGF2z06T/UztCXt6/ObK6ZNRgHVMc/LFdtG3t65ow== X-Received: by 2002:a25:6f86:: with SMTP id k128-v6mr4430682ybc.235.1542261201112; Wed, 14 Nov 2018 21:53:21 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 207-v6sm7417441ywo.87.2018.11.14.21.53.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:20 -0800 (PST) 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 v16 10/16] arm64: kexec_file: load initrd and device-tree Date: Thu, 15 Nov 2018 14:52:49 +0900 Message-Id: <20181115055254.2812-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181115_005335_877297_01CB0537 X-CRM114-Status: GOOD ( 23.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP load_other_segments() is expected to allocate and place all the necessary memory segments other than kernel, including initrd and device-tree blob (and elf core header for crash). While most of the code was borrowed from kexec-tools' counterpart, users may not be allowed to specify dtb explicitly, instead, the dtb presented by the original boot loader is reused. arch_kimage_kernel_post_load_cleanup() is responsible for freeing arm64- specific data allocated in load_other_segments(). Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 17 +++ arch/arm64/kernel/machine_kexec_file.c | 185 +++++++++++++++++++++++++ 2 files changed, 202 insertions(+) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..bbb5f505b0ba 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); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index c38a8048ed00..b433d947d486 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,197 @@ * 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 +#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, void *dtb) +{ + int nodeoffset; + int ret; + + nodeoffset = fdt_path_offset(dtb, "/chosen"); + if (nodeoffset < 0) + return -EINVAL; + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop_string(dtb, nodeoffset, FDT_PSTR_BOOTARGS, + cmdline); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } else { + ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_BOOTARGS); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + return -EINVAL; + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_INITRD_STA, + initrd_load_addr); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + + ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_INITRD_END, + initrd_load_addr + initrd_len); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } else { + ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_INITRD_STA); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + return -EINVAL; + + ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_INITRD_END); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + return -EINVAL; + } + + return 0; +} + +/* + * More space needed so that we can add initrd and bootargs. + */ +#define DTB_EXTRA_SPACE 0x1000 + +static int create_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, void **dtb) +{ + void *buf; + size_t buf_size; + int ret; + + buf_size = fdt_totalsize(initial_boot_params) + + strlen(cmdline) + DTB_EXTRA_SPACE; + + for (;;) { + buf = vmalloc(buf_size); + if (!buf) + return -ENOMEM; + + /* duplicate a device tree blob */ + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) + return -EINVAL; + + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, buf); + if (ret) { + vfree(buf); + if (ret == -ENOMEM) { + /* unlikely, but just in case */ + buf_size += DTB_EXTRA_SPACE; + continue; + } else { + return ret; + } + } + + /* trim it */ + fdt_pack(buf); + *dtb = buf; + + return 0; + } +} + +int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline) +{ + 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 */ + ret = create_dtb(image, initrd_load_addr, initrd_len, cmdline, &dtb); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + dtb_len = fdt_totalsize(dtb); + 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 Thu Nov 15 05:52:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683555 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 08D3B14D6 for ; Thu, 15 Nov 2018 05:56:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6FFB2C24F for ; Thu, 15 Nov 2018 05:56:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D961D2C25F; Thu, 15 Nov 2018 05:56:36 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 4DD8C2C24F for ; Thu, 15 Nov 2018 05:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YJPU24Gcsbtm08+5VCo2oF85qHF7Kw+F+KqKAMn2vLg=; b=kaKIdgTrec8rha UYkdSItwY/skIUXS9V1b2J0JQdtAegqBJSQkR8rDe4YdZf8J25cQ9SQL9VKAFOsPdimFXma2tDoct kllyLg8H9d5Aw5fUI4urS2ubD5ZuxE8eSaYhkeRpUGn1efAASI0P5agrHHS/LQ1MU32OS5LatiZ/w ohHbnra7bNF258cCk0/3/mP3Q47oOCPj+HbKKSQnllhM7OATw9ZPQ7l6ggkim5ANNC3+LcduhDrQE uejMRPXav3OxCRzSzN7Rke1yP8gVM9stIHhj2HgP4lyrdCRJdE9jV7TUOyfecz3XQkCMt8Fb6vByK n+4eNVq0NfopE07V/mTw==; 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 1gNAdm-0001z0-CF; Thu, 15 Nov 2018 05:56:34 +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 1gNAay-0006aU-UX for linux-arm-kernel@bombadil.infradead.org; Thu, 15 Nov 2018 05:53:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type: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=b/qBGuWcB3AvKhVU7KrMVZKitcb+1TETY1zXig3nkL8=; b=VqQDdYKbafNpoD8aeAf2XPqUVY br1SluS+WZe31/JRgZk+uOEwvGPH/F1vNGymWH3IXurbEGzYOSPhTl5cEiTiwu8kezLxVZA5FiNnG l1MoqwQKHj0A1CoTpXBS6LBNbTxIJQovyI58DB1SAr+FCFBpFfWqqy3ujQbbHaljIrAAh6eak3X4v widPB8UjXQ9r8M68qB86IVfQzfhYy89CqiLtq6+T3HoHaRLoHukobn3tcNeidrI2a3lsrWSv3EjMv usTtK4339SRbnAZW35XMe0HFFaeU2IKY5NyzCLeIQ0KaZgOp5tZB83WNcYxStYnrInBSY6RtzHVzx hrapA8Uw==; Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAav-0006NJ-5R for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:39 +0000 Received: by mail-yb1-xb43.google.com with SMTP id h187-v6so7903335ybg.10 for ; Wed, 14 Nov 2018 21:53:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b/qBGuWcB3AvKhVU7KrMVZKitcb+1TETY1zXig3nkL8=; b=ePmGRPD/oeb9REqt++JiB70heutg065ySKrqGdSWOo6V5eqn8wiA24QgJuenmDeyFk 1iU6Hqv7BMepvqiJQeneS65cQHkI+MvsNKWOLaIzc5Rn/YNWtV7FDNzLRHsuHFQLiB1e 534e/vv7LkINcd7EBeWsoB8UJ1v2seIiyR5ME= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b/qBGuWcB3AvKhVU7KrMVZKitcb+1TETY1zXig3nkL8=; b=FW1ZsrIled39DOxDfdvHXRYSyTlrc+gvZ+tYZ9cT/AG2ERdm1+2CCuSzu5LEi/k2p7 nj2r4Z4kYclEPCtFzXhV4lBQpIgygOij7+v5WOwkAT1l5JNhZUjRJX9HlcwEuxUw1a8z MjxueaU6CzdPQaIJH+HS8thtviLv+Fy0osdG//elxBmmlwULrc8K+45q0RSAWygUmHLw G0x1aHPajLZ3TXvKnqw8O2ia799IN8YiWB3zxtvyTbszOqoxZWZOjMNXYQzTyKK54k95 BCtM904NnV0t0rhdEdI9L9t+yett1WXBT7rD81gh9P6mFJuM7EBA6x27yiFkJUawxMHS YNeg== X-Gm-Message-State: AGRZ1gI4nEEUVb67m6PxQ4zpG6A5XOKVwUJQWALGy289sj4qwQTn017G 6qtSc+nwA5Y43eK68ZGB3nzCOA== X-Google-Smtp-Source: AJdET5dH4rEzZh8i+E6gSIZ0HFdqA3dZXkUlcaFjdz653JDznaf97xCNXQk2EwE2lSQ7wdDFWLbBgQ== X-Received: by 2002:a25:84c7:: with SMTP id x7-v6mr4494386ybm.230.1542261205259; Wed, 14 Nov 2018 21:53:25 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g21-v6sm7549135ywk.5.2018.11.14.21.53.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:24 -0800 (PST) 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 v16 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Thu, 15 Nov 2018 14:52:50 +0900 Message-Id: <20181115055254.2812-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181115_055337_217785_08EC0AF5 X-CRM114-Status: GOOD ( 24.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch provides kexec_file_ops for "Image"-format kernel. In this implementation, a binary is always loaded with a fixed offset identified in text_offset field of its header. Regarding signature verification for trusted boot, this patch doesn't contains CONFIG_KEXEC_VERIFY_SIG support, which is to be added later in this series, but file-attribute-based verification is still a viable option by enabling IMA security subsystem. You can sign(label) a to-be-kexec'ed kernel image on target file system with: $ evmctl ima_sign --key /path/to/private_key.pem Image On live system, you must have IMA enforced with, at least, the following security policy: "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig" See more details about IMA here: https://sourceforge.net/p/linux-ima/wiki/Home/ Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 2 + arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/kexec_image.c | 113 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 1 + 4 files changed, 117 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 bbb5f505b0ba..67e4cb75d1fd 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -101,6 +101,8 @@ struct kimage_arch { unsigned long dtb_mem; }; +extern const struct kexec_file_ops kexec_image_ops; + struct kimage; extern int arch_kimage_file_post_load_cleanup(struct kimage *image); diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 030a39bff117..48868255f09c 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -51,7 +51,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..9f0d8b5d62d3 --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,113 @@ +// 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_IMAGE_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; + bool be_image, be_kernel; + struct kexec_buf kbuf; + unsigned long text_offset; + struct kexec_segment *kernel_segment; + int ret; + + /* + * We require a kernel with an unambiguous Image header. Per + * Documentation/booting.txt, this is the case when image_size + * is non-zero (practically speaking, since v3.17). + */ + h = (struct arm64_image_header *)kernel; + if (!h->image_size) + return ERR_PTR(-EINVAL); + + /* Check cpu features */ + flags = le64_to_cpu(h->flags); + be_image = arm64_image_flag_field(flags, ARM64_IMAGE_FLAG_BE); + be_kernel = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN); + if ((be_image != be_kernel) && !system_supports_mixed_endian()) + return ERR_PTR(-EINVAL); + + value = arm64_image_flag_field(flags, ARM64_IMAGE_FLAG_PAGE_SIZE); + if (((value == ARM64_IMAGE_FLAG_PAGE_SIZE_4K) && + !system_supports_4kb_granule()) || + ((value == ARM64_IMAGE_FLAG_PAGE_SIZE_64K) && + !system_supports_64kb_granule()) || + ((value == ARM64_IMAGE_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); + + 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 b433d947d486..7e9d5ed3e238 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -26,6 +26,7 @@ #define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Thu Nov 15 05:52:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683557 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 0E9CF1747 for ; Thu, 15 Nov 2018 05:57:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA7362C260 for ; Thu, 15 Nov 2018 05:56:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D98AD2C263; Thu, 15 Nov 2018 05:56:59 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 4D6C52C260 for ; Thu, 15 Nov 2018 05:56:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VIxZtTysa182/pe5un3RN/RQBbsEafqoWuFZAKkHNFU=; b=p4O5lsiKYdOSWM sKZcd+X9bcq7roGBOHPEmlJ/6JXVaYN3ftXpKiPZg6aCTSwoB1dqdKbAwZvWj9locohpkt2FbaVhf fEEMLWn4kpMOcD5eLSEjfWFZlh5PO2dgCHPw8YtbKACf6/msi7QSx4nYLP8jg7Z7A7Q748JcYUBjp lSiAOJfl/QTrpFrPnknSeBTiPBXsJL/pfRjbtHxYBh7pojgeABDExm461Rq+uUKqI14TKkIwEpAKw dXi4ILgyTTxBCTh17cuc8tQtEOgindbXPAxeCScrzkfFhJ3EloZG9uoUq8w3IzdXhGjT5gZLSSXkY 8rGKtqsnkYhK2Wego4YQ==; 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 1gNAe4-0002IA-0w; Thu, 15 Nov 2018 05:56:52 +0000 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAb1-0006VV-TN for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:47 +0000 Received: by mail-yw1-xc43.google.com with SMTP id l66-v6so8266841ywl.7 for ; Wed, 14 Nov 2018 21:53:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M0hbeCh1UKPHriGwoJtqoIhFiJS4pqBvteNzMpOOqEM=; b=j2R2QQRzTmCm/H2I7k4eBK4g/dz0MuUN8Tu6rMbhngctlQhlCchBaEqc//rA6ZgW5p 6LvDiN/tCVGaLrs/lHTim7I4nTw6D2cmaOYnxEiqHPdW2l21rr795UQx4wEFBdW/3Ypj Xcq/MCZFRBF3DdYdwMiY3mH9hkdcbyiqO1ve0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M0hbeCh1UKPHriGwoJtqoIhFiJS4pqBvteNzMpOOqEM=; b=KIar2E4rmlpopZ58Fh4/fAPPjBLjIjjQZcSiTbd0EDLK6Wos2/8Stzp7sGrAO/GUz8 1vXhWlASqVnTQ+ri7JMe4X8tHGqRiUj/n6pWNiUUMSV566/mJlp68gxDhcUo0Vo71mDY caF2ceb8W//xwXyjaWQjPFLLOaQ6tCa80vEfvoeN+Ul0xU7kOsotBM2ItR+e65ifmH4X tyGYc+vggfZLeSHfl48r+8JUVkz5+mVIiF8oyXARt0Na7b2jyW9aeVd/7bu1whS5zbBm LYKLQZ7simfCrp4SikmHcEeNn/0OUILeYEQ84gcN81MuMVOI54Z7PRjJ2S8nIbXWDXOl r07A== X-Gm-Message-State: AGRZ1gJjPry7RNDC84qMeP64MqVQy3oe45wdjPEaXyr0Cdn/3kxS8x7J 2HCC1Q2TXND36aImtL0csBCGmQ== X-Google-Smtp-Source: AJdET5eGx2+rsQ/bswzrm571J/0BF4boo0YGryTyL1xF/XR16/BI1q0LzxGrgbLsNTLOnZ5dDytXTQ== X-Received: by 2002:a81:7897:: with SMTP id t145-v6mr4653791ywc.466.1542261212771; Wed, 14 Nov 2018 21:53:32 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s129-v6sm6769228ywc.41.2018.11.14.21.53.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:32 -0800 (PST) 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 v16 12/16] arm64: kexec_file: add crash dump support Date: Thu, 15 Nov 2018 14:52:51 +0900 Message-Id: <20181115055254.2812-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215343_968123_2F860570 X-CRM114-Status: GOOD ( 19.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , Rob Herring , james.morse@arm.com, Frank Rowand , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Enabling crash dump (kdump) includes * prepare contents of ELF header of a core dump file, /proc/vmcore, using crash_prepare_elf64_headers(), and * add two device tree properties, "linux,usable-memory-range" and "linux,elfcorehdr", which represent respectively a memory range to be used by crash dump kernel and the header's location Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse Cc: Rob Herring Cc: Frank Rowand Cc: devicetree@vger.kernel.org --- arch/arm64/include/asm/kexec.h | 4 ++ arch/arm64/kernel/machine_kexec_file.c | 97 +++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 67e4cb75d1fd..660705515e33 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; }; extern const struct kexec_file_ops kexec_image_ops; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7e9d5ed3e238..ab296b98d633 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,11 +16,15 @@ #include #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" @@ -35,6 +39,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); } @@ -49,6 +57,22 @@ static int setup_dtb(struct kimage *image, if (nodeoffset < 0) return -EINVAL; + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(dtb, nodeoffset, FDT_PSTR_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(dtb, nodeoffset, FDT_PSTR_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(dtb, nodeoffset, FDT_PSTR_BOOTARGS, @@ -86,7 +110,8 @@ static int setup_dtb(struct kimage *image, } /* - * More space needed so that we can add initrd and bootargs. + * More space needed so that we can add initrd, bootargs, + * userable-memory-range and elfcorehdr. */ #define DTB_EXTRA_SPACE 0x1000 @@ -132,6 +157,43 @@ static int create_dtb(struct kimage *image, } } +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, @@ -139,14 +201,43 @@ int load_other_segments(struct kimage *image, char *cmdline) { 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 Thu Nov 15 05:52:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683559 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 DF17B1747 for ; Thu, 15 Nov 2018 05:57:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA3B52C260 for ; Thu, 15 Nov 2018 05:57:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BACAC2C263; Thu, 15 Nov 2018 05:57:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 514532C260 for ; Thu, 15 Nov 2018 05:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yWhd6S/P6T9bDETVxIx7Qy6xAOG2Nd4vaqHKGNfyTYg=; b=skHaO/LYwP2k7Q ulw+b1DS7qOv2VxMOjcx8DHhm02dDiI2jjp1hlRGOJvNYruEhSu1zD0a+RZt3NJH91PEQ1ceN1pxJ TCsE9Q27U8pkxaGJeAbqKa8LGfMd+2lR95UNHhR3uRIoIALbimw4m8K8e0ymwB/7O+6gXgBZ1SN+U +GmOVZFGn59I7XajbZ6onxPuWgc1VvqxW9uF3a+UD4EYTCUxNm6BdATQDMSQISBnO5FI3BWmB9PMr fmTXHTiAua7eijh5eos2OXyAlu61nT2gnBsWpy9k9L+HKkjKquzwsQSFfNJFdKQyXFQpI45gBFg3g aSa04qLCd+S+GgmsrnHw==; 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 1gNAeT-0002eZ-QT; Thu, 15 Nov 2018 05:57:17 +0000 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAb5-0006YC-Dz for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:50 +0000 Received: by mail-yw1-xc41.google.com with SMTP id h32so2180856ywk.2 for ; Wed, 14 Nov 2018 21:53:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZdHE4nfr8T5Hxvr10M0CzI0OedYEfMU03IOSvEtlq5c=; b=CE5vd3ynonGHBkYw/svmJseji3AdkYx2PTsO7N8kj5DlWdgSooK8h+NeNDDgdH+woQ C+judgaQy+d5cOZH/xop4WnRz9+V6OO3FQT4orsCkiBFHZVpY/tBrqK5rWRHvyRIE+47 WiBnGGR2zA9bYIgBxZaZ17TJKE47FK6i5+vfc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZdHE4nfr8T5Hxvr10M0CzI0OedYEfMU03IOSvEtlq5c=; b=kDCivib1Idzarvn6BaJC470KLZYj8uydrNxshZvR3xsENFtIKMpM+0xe9NGJKPRbDt mS0zP6J5Y50YoUIMzWKIijkdd2eaVrKIKtrjHOOeTdN1JQFudh30PdEniF3kCobPPLK2 e+o7pstyWGZDaTLhd6XhbV14smKQDtHWI+MCeu+uBkV5bdghNMzTd6uXAPaIemnTn0Ls yBcLpZgRCTA2RdblpTUCxMJpndxkCNullI2RmqR0wPaEVlJLiKXuF4g0jLAD6zto55wc 30a3FvcQ5KbZRcsBmo2PevC6aHD1F4pw9ZRJObzEPC7uerzYThxe4pDyl0REtWl1yl7C Yo6A== X-Gm-Message-State: AGRZ1gIxOGD19aL3jqowF0gz8Hw+LDLt+1HR/aZPuk+kjqgt5A5ceW6+ MsMMX9MesALIfKkIgkonj/Lv2g== X-Google-Smtp-Source: AJdET5fGpTZnl/mRIO/GS7hi+EtTXbFnciJHECh3J0lA3SDKmagGw0cKZSNn4mSnFwmudXhop2BEBQ== X-Received: by 2002:a0d:c683:: with SMTP id i125-v6mr4713864ywd.467.1542261216503; Wed, 14 Nov 2018 21:53:36 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j65-v6sm6516907ywg.52.2018.11.14.21.53.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:36 -0800 (PST) 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 v16 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Thu, 15 Nov 2018 14:52:52 +0900 Message-Id: <20181115055254.2812-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215347_522059_9B591720 X-CRM114-Status: GOOD ( 15.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On arm64, purgatory would do almost nothing. So just invoke secondary kernel directly by jumping into its entry code. While, in this case, cpu_soft_restart() must be called with dtb address in the fifth argument, the behavior still stays compatible with kexec_load case as long as the argument is null. Signed-off-by: AKASHI Takahiro Reviewed-by: James Morse Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/cpu-reset.S | 8 ++++---- arch/arm64/kernel/machine_kexec.c | 12 ++++++++++-- arch/arm64/kernel/relocate_kernel.S | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 8021b46c9743..a2be30275a73 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -22,11 +22,11 @@ * __cpu_soft_restart(el2_switch, entry, arg0, arg1, arg2) - Helper for * cpu_soft_restart. * - * @el2_switch: Flag to indicate a swich to EL2 is needed. + * @el2_switch: Flag to indicate a switch to EL2 is needed. * @entry: Location to jump to for soft reset. - * arg0: First argument passed to @entry. - * arg1: Second argument passed to @entry. - * arg2: Third argument passed to @entry. + * arg0: First argument passed to @entry. (relocation list) + * arg1: Second argument passed to @entry.(physical kernel entry) + * arg2: Third argument passed to @entry. (physical dtb address) * * Put the CPU into the same state as it would be if it had been reset, and * branch to what would be the reset vector. It must be executed with the diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 922add8adb74..aa9c94113700 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -212,9 +212,17 @@ void machine_kexec(struct kimage *kimage) * uses physical addressing to relocate the new image to its final * position and transfers control to the image entry point when the * relocation is complete. + * In kexec case, kimage->start points to purgatory assuming that + * kernel entry and dtb address are embedded in purgatory by + * userspace (kexec-tools). + * In kexec_file case, the kernel starts directly without purgatory. */ - - cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, 0); + cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->arch.dtb_mem); +#else + 0); +#endif BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index f407e422a720..95fd94209aae 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,6 +32,7 @@ ENTRY(arm64_relocate_new_kernel) /* Setup the list loop variables. */ + mov x18, x2 /* x18 = dtb address */ mov x17, x1 /* x17 = kimage_start */ mov x16, x0 /* x16 = kimage_head */ raw_dcache_line_size x15, x0 /* x15 = dcache line size */ @@ -107,7 +108,7 @@ ENTRY(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, xzr + mov x0, x18 mov x1, xzr mov x2, xzr mov x3, xzr From patchwork Thu Nov 15 05:52:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683561 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 948101747 for ; Thu, 15 Nov 2018 05:57:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FCFF2C260 for ; Thu, 15 Nov 2018 05:57:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73FF82C263; Thu, 15 Nov 2018 05:57:52 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 C10672C260 for ; Thu, 15 Nov 2018 05:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RMICz8PdpenwZJ+Xrvc+Y+sXzw1+034SWZWNV7XVpyE=; b=peNuDaFjC6JkSi IM7K4zADFrjZps/tv6u8G29zvnfr3MpqGe3sY2f6HPUn7lGjFD2rz74wxAuNYBklChQZ00NtetkYO D/moAx+LWHzSnDhrADYB/WRi88nXHpzULNwyy9w7gv0/vE8UwdTrllbJu0wh+ri+SWk3S0/aF33s7 YTL8n74cQVKmEC/5ONX9reAXbwZW50OQymOtdUwf0LMvGO9Mr4QhJBessaDOX1TqX4eGMnXvL12o1 qyRLh62KSaADCHdKvqC17OqICf3iADlqGzTmWZjDVj2pF9fH7JLj+wNVVFCd9KFsGz2S5kTWtRZpt cc2vX5kFBMrDgfiTOppA==; 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 1gNAeu-00032G-9v; Thu, 15 Nov 2018 05:57:44 +0000 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAb9-0006ad-6v for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:53 +0000 Received: by mail-yb1-xb42.google.com with SMTP id n140-v6so7939136yba.1 for ; Wed, 14 Nov 2018 21:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IBZa+UOaDV8TYfXAr244/shDNprkQTt1AVYjh0q1zSg=; b=TU4314T9M7hEQBduv68EORGU2Ufr/Wz+AI78lNORymGpWy2/cC1Q9Il6xST8BRNKnO XBz/sK7a/7eh1YRd+LSij8lEKqoaJRFxtgBuE/CX8HLhhQR6qLgEOj7YgqO/2Zccyutn jb1KqzVxInKix5eNyz8ZQgsXNjtFPbMhmeSx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IBZa+UOaDV8TYfXAr244/shDNprkQTt1AVYjh0q1zSg=; b=CIJbaxmX16CBdQU/awyCPn1nWHkrzvTk2VnIDAM2LRvQ0EoZn2U/yPvVDjBmv4nVLr VqSZac0iyt0VRKhP5o0oXd3VlZ316QCr8BvzrVpnIm+8PqDtqJDRCP7iVGSWA766Z69Q Ae9liNQ9QwBsmJjCqRByc3yo1KejQDyqi+VtjvOY7dPkkdpwslbdYYyTJBNGoWr7Y4p8 lj0G0nUObGLtMJisJkss5UapRvsI/k/6zD2ICzx02xVQuITf6nvk+h+JNplRR+3Cm1hn 6JfYaITbw6bHDmjfBFdXSfsg4Go4HC7iLaJm4djdTQkrkdpSy+YTsEaTfJW0q1laEJ0J SsCQ== X-Gm-Message-State: AGRZ1gJ/1CpKKsoNiHFNCaA3PSoKA04EkWvogDXb/ETBf6xBkXLyFqsI I97JfnAgksd9QQEnxDVuKE+gAQ== X-Google-Smtp-Source: AJdET5etu9Ve+mcscEGVR9rqWITSQHqUdYahtPNsjVEWwwfcX3RByj+ZV1uDb7VWQpMs1OBlX6qFfA== X-Received: by 2002:a25:20c6:: with SMTP id g189-v6mr4548113ybg.196.1542261219743; Wed, 14 Nov 2018 21:53:39 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p13-v6sm7297817ywg.12.2018.11.14.21.53.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:39 -0800 (PST) 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 v16 14/16] include: pe.h: remove message[] from mz header definition Date: Thu, 15 Nov 2018 14:52:53 +0900 Message-Id: <20181115055254.2812-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215351_270473_B686ED44 X-CRM114-Status: GOOD ( 14.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP message[] field won't be part of the definition of mz header. This change is crucial for enabling kexec_file_load on arm64 because arm64's "Image" binary, as in PE format, doesn't have any data for it and accordingly the following check in pefile_parse_binary() will fail: chkaddr(cursor, mz->peaddr, sizeof(*pe)); Signed-off-by: AKASHI Takahiro Reviewed-by: Ard Biesheuvel Cc: David Howells Cc: Vivek Goyal Cc: Herbert Xu Cc: David S. Miller --- include/linux/pe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/pe.h b/include/linux/pe.h index 143ce75be5f0..3482b18a48b5 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -166,7 +166,7 @@ struct mz_hdr { uint16_t oem_info; /* oem specific */ uint16_t reserved1[10]; /* reserved */ uint32_t peaddr; /* address of pe header */ - char message[64]; /* message to print */ + char message[]; /* message to print */ }; struct mz_reloc { From patchwork Thu Nov 15 05:52:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683563 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 4CA891747 for ; Thu, 15 Nov 2018 05:58:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34F592C260 for ; Thu, 15 Nov 2018 05:58:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 251082C263; Thu, 15 Nov 2018 05:58: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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 9D7542C260 for ; Thu, 15 Nov 2018 05:58: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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=emG2Odxd6H+VNPrPzPhioKFKXIlz/SVPz/jz6TTlOZ4=; b=QwEtkxmIta34xG 8vubX5PaETJa3J5etxtpU3Ks8Xzuy52wVgpAJM93tBdzP8yF5wPLv3vZTjB6RoH77LrHaMt+46dZQ Jy0/6YfFBYMsL4XOTJrURPLzo+AvUYdcMcE16cQ7rV5HfKYQ6wSPfBcMJT53MiLp3dW6Vvu/w2u8t m3kMmI1O1R6gUExSSNLJ5eD/QGHiKZX5Z4bzWcY2hMlfv9JYCMHy4xN6yyCKQoLgIc1V7VbuNKRVB 5eHwZacf+9KJX35VY1kY8tfd/GoEsrWUlvNFfXzPfEAWp9sbeYSIW/l2RxP2hAq8cixwqEDRkg1BU aO5sIVBdHEYkcX2K8pdQ==; 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 1gNAfH-0003Mq-JF; Thu, 15 Nov 2018 05:58:07 +0000 Received: from mail-yb1-xb41.google.com ([2607:f8b0:4864:20::b41]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAbC-0006da-GZ for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:53:57 +0000 Received: by mail-yb1-xb41.google.com with SMTP id h187-v6so7903533ybg.10 for ; Wed, 14 Nov 2018 21:53:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9P53Yj/xMXiy2VwbQPz0MnQUBccWU//quNYW0Ks+uWQ=; b=RuBj4P2KtbYJ5z9USSRs+7o18nA+07+01QwFh3UtWxMpEjf1sRCmIJdKeu9F7Dxe0b U4yhq1t6E5RWWBnY3EVAbaOpN+RsBs9HGRli3CY50P6r+V5BdeUIq1m6yrvOhnrJ4Snz kVhrmv1hMMApkndiuBYd7IAa8gpBE9Wml7WoY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9P53Yj/xMXiy2VwbQPz0MnQUBccWU//quNYW0Ks+uWQ=; b=cJuUnWESUco1mjB87yySFOrbioZ6Ic0e5RKy6jiyy1nM0g2xnrbv0oI+ddciDIYbAc XfJ/nOdiJHYWPKJAf0bXR9ejdLVwcaCnbmz8UkZB8nVQhgiBShgnnbduDsmQno3kzluR 19KbXdVLUlimwyRya3LUGMTR6AmE64n+a1GO93Dh3+ScAnwYOv+cxWLw+cDkZbygdtIa V8/CQHjDz6lub0obYH+JOQi17GQNtWW05aKc8PCCHX+dPyRIZJtE4iYOH8W7RPYtMwVk sbL5SQkk23XMt/8DJTqRDks+focaOiLBfr7/6T17Ux3Xl+/TpTEGs6kyPitlWpWStel+ u/Gw== X-Gm-Message-State: AGRZ1gK23TR8n8b2BYc5Y3kj1QeUkMOe0v+T1yXUjT9ItLnl4CVksFCR gdK7etCItOPfP5xBY7PTYW45Cw== X-Google-Smtp-Source: AJdET5fFdK8szs+B+qUJ3wdgWiLE4l4gaPySkRnftc2+aZxbkCEKtN3WDr30shmkoLh8Q0v+ims7Og== X-Received: by 2002:a5b:40a:: with SMTP id m10-v6mr4520102ybp.21.1542261223143; Wed, 14 Nov 2018 21:53:43 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l35sm1837306ywh.48.2018.11.14.21.53.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:42 -0800 (PST) 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 v16 15/16] arm64: kexec_file: add kernel signature verification support Date: Thu, 15 Nov 2018 14:52:54 +0900 Message-Id: <20181115055254.2812-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215354_592167_148EA466 X-CRM114-Status: GOOD ( 15.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP With this patch, kernel verification can be done without IMA security subsystem enabled. Turn on CONFIG_KEXEC_VERIFY_SIG instead. On x86, a signature is embedded into a PE file (Microsoft's format) header of binary. Since arm64's "Image" can also be seen as a PE file as far as CONFIG_EFI is enabled, we adopt this format for kernel signing. You can create a signed kernel image with: $ sbsign --key ${KEY} --cert ${CERT} Image Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/kernel/kexec_image.c | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 93dc4d36d6db..11f3e1a00588 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -867,6 +867,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 9f0d8b5d62d3..d1c6c54c22e3 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -12,7 +12,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -29,6 +31,10 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) sizeof(h->magic))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&((struct mz_hdr *)h)->magic, "MZ", 2) ? + "no" : "yes"); + return 0; } @@ -107,7 +113,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 Thu Nov 15 05:52:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10683565 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 E5CB514D6 for ; Thu, 15 Nov 2018 05:58:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D23A72BD8A for ; Thu, 15 Nov 2018 05:58:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C498E2BEF6; Thu, 15 Nov 2018 05:58: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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 627512BD8A for ; Thu, 15 Nov 2018 05:58: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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=48ze4iLWJxXa4UuUYaMfoE6Y5S2NYdIpxV/1+HJ9NgY=; b=Lm8xTIELBfuXwK i1JkMJ72BnSQg+pi6r6zIbnkwtUuXr5LgUcoppzNtGVTpdgV6DKMobcHmvoSzXqNjKoQpC+c7lLIV jG6t8wspJ9sZMFxi2d3U/HdEIZvdDdnHS8vYRypea+01CdseQ30hbC/sOrEAVkvBRfESTwMow8sAv z7y9f9iCRjoWUIQICN9CSNR0EuFTlocpGZMreBWWkG5omxDYx0rlYKiahRxRY+Kt0x5yKQfAAWWCG BQ1hUN+jiMWoomk9Wodo/YlMnoObc55uT/RuPoaGnrVGNo0/7EtMzoQ+83+kFupYHpqrHd8Vxf0Bh lFKScSB6bAqhVMy756JA==; 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 1gNAfb-0003fi-Hp; Thu, 15 Nov 2018 05:58:27 +0000 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNAbF-0006gC-Ks for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2018 05:54:02 +0000 Received: by mail-yw1-xc43.google.com with SMTP id l200so2683288ywe.10 for ; Wed, 14 Nov 2018 21:53:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z6fpkRKvJjJuOzp7wHTBqPrWgQFd+w1vM5L/3Tpwhps=; b=NsKJ0pnbz1wxK7DAjNL7ynj+T731invAf4RnUN/pFf3mEkpgElVGh79yv/MP4BIjW9 oMsjLQBGyoTfTSJrQ+CIv2CP3QDoesQIUj+Wse6zWsLaY2Vx6tWHv7U0Z4oyZXlB/3vU K9LtUxww4zddwC7VpMa1XzXmlpqRwG5oiLy8k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z6fpkRKvJjJuOzp7wHTBqPrWgQFd+w1vM5L/3Tpwhps=; b=eo4ySPThXrNxc68U6wXbqUitLCuhZabhAvTBbbWcAIHHJijYQNpXwHTlAszVKDUdAF nK58yI+tDLzwhvlnNgWzyY2GN21P/QETJW59kWoMDB69jxbPtzxBByLQZgsw4tmui+hn wCNpjwO049YwZgYaxeHa+L7RlTJ3l2VMy9iEM8NzXXVvLw/ImH/Xg3DfIoJcC4BSD7Ij e83koSZlc7FuZEPIGst63wpnwy1OiJ3Mwzh58blHYJNt1+9H0hvVPHZ+DbRqpG2uF4+G lrF6KsEF1eMvEd5uF1spc1lf2Aeu9qUp8gWMH1Z0T7fbrxtsY2QYBE6RN/Q6Jj0xLb7i 9EWw== X-Gm-Message-State: AGRZ1gLTh+N14R2pDjvACNZW0KRT3Wu9OvQeikiPyzK1zP2EC3T0PwQ0 pRziJRcvb26ZmeMpqAiai9Ur6g== X-Google-Smtp-Source: AJdET5dRF8aftl5JbSuc+XrJ2uCh54qihW81ZcVe7oEYrH0/OUXVxTU9B5EZOYh77ZobH769wki/1g== X-Received: by 2002:a81:26d4:: with SMTP id m203-v6mr4471570ywm.327.1542261226677; Wed, 14 Nov 2018 21:53:46 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m123-v6sm1526751ywe.86.2018.11.14.21.53.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:46 -0800 (PST) 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 v16 16/16] arm64: kexec_file: add kaslr support Date: Thu, 15 Nov 2018 14:52:55 +0900 Message-Id: <20181115055254.2812-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_215357_693713_087270CC X-CRM114-Status: GOOD ( 15.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 46 +++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index ab296b98d633..a0a730bd9be6 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 @@ -28,6 +29,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, @@ -46,11 +48,38 @@ 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, void *dtb) { int nodeoffset; + u64 value; int ret; nodeoffset = fdt_path_offset(dtb, "/chosen"); @@ -106,12 +135,27 @@ static int setup_dtb(struct kimage *image, return -EINVAL; } + /* add kaslr-seed */ + ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_KASLR_SEED); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + return -EINVAL; + + if (random_ready) { + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_KASLR_SEED, + value); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } else { + pr_notice("kaslr-seed won't be fed\n"); + } + return 0; } /* * More space needed so that we can add initrd, bootargs, - * userable-memory-range and elfcorehdr. + * userable-memory-range, elfcorehdr and kaslr-seed. */ #define DTB_EXTRA_SPACE 0x1000