From patchwork Fri Sep 7 07:56:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591829 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 5B712112B for ; Fri, 7 Sep 2018 08:03:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D9282AD5A for ; Fri, 7 Sep 2018 08:03:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 415CD2AD5E; Fri, 7 Sep 2018 08:03: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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DF8A02AD5A for ; Fri, 7 Sep 2018 08:03:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=mu2W7qPpCIlOZTxuyT1oEmo8SCMNFykgYRZ68hFnXHA=; b=ukFKe5JsFouzoE64TPoZM89kZS 1hwUy7l+nugkZJjKcJ0GRI2AAGjoMbUN4iHB5vKMtfJdjsCzPSsg1IeUzNHlraI6ypVXKOq8HLA73 eP2aFG0HAtoFrJueWZ43u1xlN9f99P5kEyY6LA4CX1wSolkS7HX0X+XU35Q+xHvUxLh+37JqVmBCq otyGxMdNMQu4GgfjcRymmyBvp11nYpQ8OLyMAcU0SLy2K5odBkLXFZciMRs1uVFuUlT1Cef6/6j/u 0tVQ9FibUDOwHoSyZQUQf1LDWpiF0tPZONyvMTyVyzYx4V02PEA9F+fqWpf/zHYtU+TdjSRflH2b9 q39YqdHw==; 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 1fyBjf-0003KL-Uu; Fri, 07 Sep 2018 08:03:23 +0000 Received: from mail-pf1-f196.google.com ([209.85.210.196]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBgq-0000pq-JW for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:00:32 +0000 Received: by mail-pf1-f196.google.com with SMTP id h79-v6so6617207pfk.8 for ; Fri, 07 Sep 2018 00:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=Vrs7iPZaJs2lX7U8ETOMXsv5z2KiZmr2IZAgRk2mnxfHL1v2nrLT18bqKI8Eg8Uv5l 0Ik6D/GqZpiGZipS29hvfmytB2YBkFmVbfrny6kOaANMXudo3ez/gpzvTsJIuqqu9aJ4 PFJS+uH491XkCYfqNC5s1RlwuoiCpGd6aAf8A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=DZSrA7yyYeVzX+ZCkw6q5b3dAoPWvXR4BnsmEWIGFKjAIwb+UlMGGkxWg7yM6FzE5a qarAubbEe/bryKSMMNayrTCENY6GB1vKpO0NuKr+Q7n/fq6FjkXxeidXcmKVNLuLkaFg YX6D79JFAKGWWJGd4Q/otGCn5ZovlWGPZWPoYs6ju0RyoUudOnimDcRrsWgje71+pZI6 yQa2zJpXAyW3ll4/48O4kzh5lo5fOweYBIakXaVmlapfjqb6WcN9+RQOmG77XBWQCmLT nnfZVQ/Sg4SDBCm/UNH7LlY0uHguhjpSUQGBBtZXcYQ3Uj4UIBM62+vu2SsOwMx3wK2z Oh6Q== X-Gm-Message-State: APzg51DupxhvZ7fFKRxRWHbwWmjn0fTwNmLHHu0dpfT2diCGlQUZzCTt o7A9L9Vtl94KrKqtEdtHziYjWQ== X-Google-Smtp-Source: ANB0VdbCgm41LDZoU8tOguOWLvaYE1LKIBw9q9WLBZ3VcVy65hAu/fzYGTFkbGjE8BVPneGB2L53PA== X-Received: by 2002:a62:1605:: with SMTP id 5-v6mr7168821pfw.11.1536307037247; Fri, 07 Sep 2018 00:57:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x9-v6sm12684384pfd.31.2018.09.07.00.57.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:57:16 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Fri, 7 Sep 2018 16:56:38 +0900 Message-Id: <20180907075653.4696-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010028_656707_BECF8B5E X-CRM114-Status: GOOD ( 10.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The initial user of this system call number is arm64. Signed-off-by: AKASHI Takahiro Acked-by: Arnd Bergmann --- include/uapi/asm-generic/unistd.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index df4bedb9b01c..acea91e49523 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -736,9 +736,11 @@ __SYSCALL(__NR_statx, sys_statx) __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) #define __NR_rseq 293 __SYSCALL(__NR_rseq, sys_rseq) +#define __NR_kexec_file_load 294 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 294 +#define __NR_syscalls 295 /* * 32 bit systems traditionally used different From patchwork Fri Sep 7 07:56:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591843 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 4205B112B for ; Fri, 7 Sep 2018 08:07:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 344B92AA89 for ; Fri, 7 Sep 2018 08:07:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 288EF2AD5B; Fri, 7 Sep 2018 08:07:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67AFF2AA89 for ; Fri, 7 Sep 2018 08:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2lpyGd3njXQWO6NaEzM8LSzZb/0StDiNmH2jVwLsPOs=; b=Ht8PEnVZitit1RYDlIly8aU578 koeQdYx9C27ErgoBHQI8HkgWZyASu4GMmwyfZm1XkEgiynAzhu6Y3chUu3SlZFJs/qZfcJcdzII0C w0IeIL+90KBLCunnmE7bfEn/iyXX9csC7G6n/Gzc2ynYnoenZuIEHW44gY4CcJGuQprdQprX11Bf2 1+He5GuaejEn9Nx1mKyRPjAuJl0uxcAAvsMSR1uZierH3I7gONt0/eUJPTSsly7faBvrOTta0iJDS y4ZMOBX/M3MZv7Tq9Sd0uzxt7UG7/Z63Jd1MnjQpkltpgl8hRCNAeYpEi89swvWI+4VG3C7Glx/mU njYZGpzg==; 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 1fyBlH-00043R-DF; Fri, 07 Sep 2018 08:05:03 +0000 Received: from mail-pg1-f172.google.com ([209.85.215.172]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBh3-0000ud-UI for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:00:48 +0000 Received: by mail-pg1-f172.google.com with SMTP id 2-v6so6603172pgo.4 for ; Fri, 07 Sep 2018 00:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=QT7DAb1VW3TTiSKno3oN+Ds4oOesrprs8hlPrzWly0uu8ex49FZI44yQkoCeR0AXlO rybOkj+45dEks0DMV0i9PMQOIkw6nwa/FjlkvSv4OVSPeAJXQMgs3oMmfIxbSwMei4TJ ARQiZQOCdCx9TdJVynK7qupICR+kH/Nwc/Ic8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=qDFVHwb++iBv1V5C3NOZwAkIPGDyDc/qYhzecdmCWwGbmABgMcYvLKmj225myPHlsw SSAFNtcpSyviNBVgRzltigcPasNu+SYL8O3ViwaiXIdTUQ7bJhU/Bc5Mh4nI/LTqKExb ekLUwiwnpo8D9tHr3S217LRZFQHI5F2H//YLY4sjBeemJt4HS8CalXjkab2ndlCsp1s7 sOYKeFZ4BaFKIOQcnyRZXujtsz/TO27MOm2iSW96UO6UHZwiNNftPmqIU6XOXO4f76br mGvRfglta5IjgTfPRjOCYO59DVLQk6kSUJR8NuA6kIXGEUWbg7trOxkB07FWJuF0XEFr crqQ== X-Gm-Message-State: APzg51B2vbEpFZ4uN4vc4/ZdXIZ3Ino198I42Dcao6IxnJTREPJlmfpZ IzG/Qa+ZOSKV+a22+Mjf+LxWhg== X-Google-Smtp-Source: ANB0VdZKCSZYPTHErK18CnoV+IImlHiXf3hiM7VeJ1mpWoKXKrCERdaZAtds77TdKqODX62E2tFSiA== X-Received: by 2002:a63:555c:: with SMTP id f28-v6mr6968922pgm.37.1536307050029; Fri, 07 Sep 2018 00:57:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q26-v6sm12593771pfj.127.2018.09.07.00.57.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:57:29 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Fri, 7 Sep 2018 16:56:39 +0900 Message-Id: <20180907075653.4696-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010042_019577_37DDE346 X-CRM114-Status: GOOD ( 12.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Change this function from static to global so that arm64 can implement its own arch_kimage_file_post_load_cleanup() later using kexec_image_post_load_cleanup_default(). Signed-off-by: AKASHI Takahiro Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- include/linux/kexec.h | 1 + kernel/kexec_file.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 9e4e638fb505..49ab758f4d91 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -143,6 +143,7 @@ extern const struct kexec_file_ops * const kexec_file_loaders[]; int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); +int kexec_image_post_load_cleanup_default(struct kimage *image); /** * struct kexec_buf - parameters for finding a place for a buffer in memory diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index c6a3b6851372..63c7ce1c0c3e 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -78,7 +78,7 @@ void * __weak arch_kexec_kernel_image_load(struct kimage *image) return kexec_image_load_default(image); } -static int kexec_image_post_load_cleanup_default(struct kimage *image) +int kexec_image_post_load_cleanup_default(struct kimage *image) { if (!image->fops || !image->fops->cleanup) return 0; From patchwork Fri Sep 7 07:56: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: 10591835 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 D7FFA112B for ; Fri, 7 Sep 2018 08:05:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C943C2AA89 for ; Fri, 7 Sep 2018 08:05:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD19B2AD5B; Fri, 7 Sep 2018 08:05:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 141772AA89 for ; Fri, 7 Sep 2018 08:05:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=SR4uPc0+2vXY2cfqo796YhxA30Lq4y46mpCObk0wprE=; b=l1BTRa8jzvszc9tyeDMbqftR/D PzWfGWyCW4SHxbgF4NBhyAnxOBuRoN8P0pPrLK4xrMf6AxAkHvQ1qsN7kofz5LXtpC1FaUHSL1E9v AQewMTlBTLTCNTt0ZBcTAyWDMmhP1YpVu5MJauudaDq6Mbxs1xMBiP7r9EbxtKRUiBP007WADuadK 8W5xaCu8HDZbuAAxRDkl74rszP728X8Xi26nqD4msAFpWTYrTZBWJhT3LzjBNxmQGr4jaecws2gsb Gf3sMlb7XLLtjGTbhVV64vHl9pa8mJPL7GYeAxbe3AOt70il3ReCQTr8U3bfRmBG7fbBpXKeQfgQU QviwcCQw==; 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 1fyBlq-0005Vq-JL; Fri, 07 Sep 2018 08:05:38 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBhT-0002sM-Ru for linux-arm-kernel@bombadil.infradead.org; Fri, 07 Sep 2018 08:01:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=UFZdSzOBCDhCucMx9QLxaQGXbSUDnlXX6wiHP7BXxqU=; b=zvLqg86WNG2rGYcCsa1GkRhNo tpXV4QGcivwpZClQ8NrqQHCeKlmqEI1q9P8reYF1HaZfcaPMcUcQ3iD8u3CtROmB49CaRCRAQdIcK t2yumIfcseGrt/Vn2siZEgdcF+IUtbhmSME1H5mgkbIKLHhV3d+BlvOYAzE9aejR5KV8Yog2HnM4A 7mdi4/ISgluCtB9hOR94nC8JEQmm+kd2I6YWlAq7r3G/gEUl3gS6DHUoOZI8Sb2aD6aK7/3L68QOw yZzcReLMVaONpRvXV53xnBnX3e1beScXuxyI34lv5n8YlTB7Ak9LzED1/G6+XPFfKFhVl4Yp47a8R LB7q8eF4A==; Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBfM-0007wq-Ma for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 07:58:57 +0000 Received: by mail-pl1-x62b.google.com with SMTP id f6-v6so6241969plo.1 for ; Fri, 07 Sep 2018 00:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UFZdSzOBCDhCucMx9QLxaQGXbSUDnlXX6wiHP7BXxqU=; b=NcvFPXdYdZnDZNUVaQmm1LA4c2cwtD4jx3+WjEo8Va01rghMCP75wL98HCDEiKEYvr gafPvWw6Fq5vvgw1w6y3oLFWGyMnKqI+8chfWup9dmIjcNopmB2AM6xhsOdh1VACxtHz mIx7zRckOMd9qDkvOk9BiiHRfQ7z7O5wM+3TU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UFZdSzOBCDhCucMx9QLxaQGXbSUDnlXX6wiHP7BXxqU=; b=c2Bd0l+XKGWtxNvID6FMnMeclf6MeaOIxts6sYu6T19Xcs48ElSOyI7qSAneSmclwq rny0SHaci3zrwTZiLf/OBe5LiBGY1k6biErSybzz034+DbXtXncPZBH9zYGD2Fl7gg2c QZM+3GXPJwtiw2YNsqmwD+LMORlQAx1XODDVo57NJOeCUNc9thvWDM9QudNiW4EZ6paJ wvdKTm91cNHuMmGpoNg6Rt+5PijHj+9+3UaK0Vi82c/pZ+JI2S9k+SwT/oCq/Hhk3lvD 2ZNSPra2URaBW0erUcc5r2qWqVHAlETRMT7w11FN/UUUZXTJgk5wkap2O4tnplHZouf/ IMOg== X-Gm-Message-State: APzg51CwpEflvemVSx3+8PV19KfE+aFzmHFvh9D0bgOD+WIMkD/uJTyS lZ1SRVrXlAge+OOjg2qTW1GK7Q== X-Google-Smtp-Source: ANB0VdZfil51JUnpmyhtdzSSLzTm0D/G1dShFjmbF9UAvtCZSnPX7baPMcWHq0drrGHkqyRQMTA8jQ== X-Received: by 2002:a17:902:5a87:: with SMTP id r7-v6mr6601602pli.247.1536307060716; Fri, 07 Sep 2018 00:57:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f87-v6sm19872299pfh.168.2018.09.07.00.57.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:57:40 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Fri, 7 Sep 2018 16:56:40 +0900 Message-Id: <20180907075653.4696-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_035856_756353_3268F0B1 X-CRM114-Status: GOOD ( 20.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Since s390 already knows where to locate buffers, calling arch_kexec_mem_walk() has no sense. So we can just drop it as kbuf->mem indicates this while all other architectures sets it to 0 initially. This change is a preparatory work for the next patch, where all the variant memory walks, either on system resource or memblock, will be put in one common place so that it will satisfy all the architectures' need. Signed-off-by: AKASHI Takahiro Reviewed-by: Philipp Rudo Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- arch/s390/kernel/machine_kexec_file.c | 10 ---------- include/linux/kexec.h | 8 ++++++++ kernel/kexec_file.c | 4 ++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/s390/kernel/machine_kexec_file.c b/arch/s390/kernel/machine_kexec_file.c index f413f57f8d20..32023b4f9dc0 100644 --- a/arch/s390/kernel/machine_kexec_file.c +++ b/arch/s390/kernel/machine_kexec_file.c @@ -134,16 +134,6 @@ int kexec_file_add_initrd(struct kimage *image, struct s390_load_data *data, return ret; } -/* - * The kernel is loaded to a fixed location. Turn off kexec_locate_mem_hole - * and provide kbuf->mem by hand. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - return 1; -} - int arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section, const Elf_Shdr *relsec, diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 49ab758f4d91..f378cb786f1b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -145,6 +145,14 @@ int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); int kexec_image_post_load_cleanup_default(struct kimage *image); +/* + * If kexec_buf.mem is set to this value, kexec_locate_mem_hole() + * will try to allocate free memory. Arch may overwrite it. + */ +#ifndef KEXEC_BUF_MEM_UNKNOWN +#define KEXEC_BUF_MEM_UNKNOWN 0 +#endif + /** * struct kexec_buf - parameters for finding a place for a buffer in memory * @image: kexec image in which memory to search. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 63c7ce1c0c3e..0fcaa86219d1 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -534,6 +534,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) { int ret; + /* Arch knows where to place */ + if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) + return 0; + ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; From patchwork Fri Sep 7 07:56: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: 10591841 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 796365A4 for ; Fri, 7 Sep 2018 08:06:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 691682AA89 for ; Fri, 7 Sep 2018 08:06:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C3E52AD5B; Fri, 7 Sep 2018 08:06: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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7406B2AA89 for ; Fri, 7 Sep 2018 08:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BUxMD7PGIFWymfEF1xegh/WwHFwugidv0+nra3c4ArE=; b=N7pSJZ0SqxpaXln2sMIcyMbBdV FOjZOeKborSza7AP3nBZe8JpM9oLD00AjtLkiiFCyZR1oEru5gQTCQFshPjOffdvSog9kdg9ecO7a MTsChhZInU7W+0MJdhdF2MQBrQ+AOr5yGVgR/5i1rJJuQ6cP7ox8yQbLWwBUZP6BZAXCL8BDSjl3J CJO70CnzxGRMJ0YGwKHyEHcuj+df6Ym+U/p31GXlEs9nBQjTLPdOfEo1YFJ44UwrpQku4UghhMdgd KZFRMgs0iqcbsMud/I08XtHwOJ2obhG8MGbIHBseI5k7cCRzp2VPopJpiG6OaKbnkUcGiBG/9duld 31vnX22w==; 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 1fyBmv-0005xD-0I; Fri, 07 Sep 2018 08:06:45 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBhg-0002xx-7o for linux-arm-kernel@bombadil.infradead.org; Fri, 07 Sep 2018 08:01:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=G9kYri4+HK/HIbj9APwd9ezqkNFakYGkDtWst37y2L8=; b=mcwGk9gU2VyFoQ9d2PDNLnRRC mS8IGgsXIFvbYTayOPZbNwS/sUF91P9FdrDLgrjDbK+kGmaKBMj0gHUQU8B7IdDZwx4pTcsPL7aQB /0gNY+3Qvg4K1cERkh8mJ9Q/3Uml1d6jhsBS0KyIRr/OWLLzz9E0h1ESI0/BxQFQc9NdLH63gbdex LXKu45XeojzGcZQFGzlEzgCs/7E6wpMayY//McwLaqEc7+qWACbyCIil9K2xw6fcf+WGBfDFZPJaE EODAOIuK6bAMapEbXQ4xOgD0ReNXxdUEMYDGfDAb1y+3Yxqag4Bkw53VZXuivOEu+1P2S9miA5GoM 3g/Cuoejw==; Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBfU-0007wz-Vv for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 07:59:07 +0000 Received: by mail-pl1-x641.google.com with SMTP id f6-v6so6242179plo.1 for ; Fri, 07 Sep 2018 00:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=G9kYri4+HK/HIbj9APwd9ezqkNFakYGkDtWst37y2L8=; b=kyWSI8rSFfgNg0CEdOxp9hp3SeZ3F0IwNKz8gD27leOk0eBv2DgXp9yNqdfEAqn1UP 4kb2MFG4MO6IssGsYHWe8obziOcqhHFLc6rNqvr+zJ5qN9GSh7mWtIdiJEyb6YH+dIr0 PwV43kQpA1KwSwB1Gu1EIvYH6DntwxvoOs4wY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G9kYri4+HK/HIbj9APwd9ezqkNFakYGkDtWst37y2L8=; b=WTy1I+rGdiOkGdhmQtRUACkbY+aYfcJ0hR2tYnkzOhG9KGRLXvSTZppHGw9UyvrFID +snwzDpO1A8teUos3rcghK95FxAj2b1vo8pQn0qbwABP6GkAjEq3yYu4spGzJBo8N3Vy R6wbPu8y/0J/OGzgo9nio/kd8hc4rNmZS3/ePVjgsltVK7S6ZY1Obnbc9vB1rrblwqcR DX8dN9pKIK0sZQEsUVBPeN7AFfWxtV+v+ISsVTxpB/28+cFMB/7vKFs8hwhbobbq9mT6 0qFRumISuaDJ7k3KPBwKHibZt2qye3VzKAIiSZbjNpxz5u44VmVQfwsvpKxxm/XhqcK3 35tg== X-Gm-Message-State: APzg51CfAvPIHdq5jxJIKifRqJguJOvwgAcvBSBrgD5juxvAtHU2FrFi S6sy8Ii9dFgezyq9mtMKYgWTVw== X-Google-Smtp-Source: ANB0VdYNWXLcFP99LOHmxLI1EnG7ZmEpuejYUhI9SCfH/jFYANhAeCnv2D8nk+bxRMLQj+upr4VcKg== X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr6659044pln.60.1536307072468; Fri, 07 Sep 2018 00:57:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y18-v6sm8498519pfl.90.2018.09.07.00.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:57:51 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Fri, 7 Sep 2018 16:56:41 +0900 Message-Id: <20180907075653.4696-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_035905_067581_AACE0D74 X-CRM114-Status: GOOD ( 25.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, "Eric W. Biederman" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Memblock list is another source for usable system memory layout. So move powerpc's arch_kexec_walk_mem() to common code so that other memblock-based architectures, particularly arm64, can also utilise it. A moved function is now renamed to kexec_walk_memblock() and integrated into kexec_locate_mem_hole(), which will now be usable for all architectures with no need for overriding arch_kexec_walk_mem(). With this change, arch_kexec_walk_mem() need no longer be a weak function, and was now renamed to kexec_walk_resources(). Since powerpc doesn't support kdump in its kexec_file_load(), the current kexec_walk_memblock() won't work for kdump either in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 ------------------- include/linux/kexec.h | 2 - kernel/kexec_file.c | 60 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 59 deletions(-) diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index c77e95e9b384..0d20c7ad40fa 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, return kexec_image_probe_default(image, buf, buf_len); } -/** - * arch_kexec_walk_mem - call func(data) for each unreserved memory block - * @kbuf: Context info for the search. Also passed to @func. - * @func: Function to call for each memory block. - * - * This function is used by kexec_add_buffer and kexec_locate_mem_hole - * to find unreserved memory to load kexec segments into. - * - * Return: The memory walk will stop when func returns a non-zero value - * and that value will be returned. If all free regions are visited without - * func returning non-zero, then zero will be returned. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - int ret = 0; - u64 i; - phys_addr_t mstart, mend; - struct resource res = { }; - - if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, - &mstart, &mend, NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } - - return ret; -} - /** * setup_purgatory - initialize the purgatory's global variables * @image: kexec image. diff --git a/include/linux/kexec.h b/include/linux/kexec.h index f378cb786f1b..d58d1f2fab10 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -192,8 +192,6 @@ int __weak arch_kexec_apply_relocations(struct purgatory_info *pi, const Elf_Shdr *relsec, const Elf_Shdr *symtab); -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 0fcaa86219d1..370d7eab49fe 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -501,6 +502,55 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#if defined(CONFIG_HAVE_MEMBLOCK) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK) +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + int ret = 0; + u64 i; + phys_addr_t mstart, mend; + struct resource res = { }; + + if (kbuf->top_down) { + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + &mstart, &mend, NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } else { + for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, + NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } + + return ret; +} +#else +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#endif + /** * arch_kexec_walk_mem - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. @@ -510,8 +560,8 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) * and that value will be returned. If all free regions are visited without * func returning non-zero, then zero will be returned. */ -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) +static int kexec_walk_resources(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) { if (kbuf->image->type == KEXEC_TYPE_CRASH) return walk_iomem_res_desc(crashk_res.desc, @@ -538,7 +588,11 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) return 0; - ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); + if (IS_ENABLED(CONFIG_HAVE_MEMBLOCK) && + !IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback); + else + ret = kexec_walk_resources(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Fri Sep 7 07:56: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: 10591851 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 7F0B0112B for ; Fri, 7 Sep 2018 08:09:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 704BC2ADC6 for ; Fri, 7 Sep 2018 08:09:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63FDD2ADD2; Fri, 7 Sep 2018 08:09:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F03872ADC6 for ; Fri, 7 Sep 2018 08:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1dCNhZc73WeIz2z0zseZdpfr/EoSzT8gtkFmenZiZDQ=; b=G5OgHu+O6dNZ7HDZ+5wcnzJpS2 8mMSdI0AZQpH6BsTXimbZNkYAzbTKX91mIpg/sEtL/pG2pWQQ/WvhpcbkbgT09wdAH8/BTK6NB+Aw UKOOsePmwVIB1mYL7rr+uGNLiScU9BBZzH/IchBqerV3VAyWAOblwhNakmXiMCUeiPiZZTJ8mhs47 sPKyXtd6yEEMtsM0uQxSqrdr4RtKzgJ88SfhdReWqQgQlC1jX+TL2u0+j+L4dtFeg3DyLFGoMHB/d EFcI/z/a+BnC0VXxIxM3bUHFAXqefKl90OfYRyvk0eAzjzgHlk3r9bA3Tiib7Z6wbHpb+dullETqU rn6IJMSw==; 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 1fyBoo-0006mz-G4; Fri, 07 Sep 2018 08:08:42 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBho-000321-BL for linux-arm-kernel@bombadil.infradead.org; Fri, 07 Sep 2018 08:01:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jeWHjhWZzqcn992r+CjxadoTg1glUklXZIt+KkbfGzY=; b=XRcpeNoTnML0qxwuabxoAUN83 A7ACpKXiKZSkw/cUUZXOPlkQINNmIL1yBuy4yg6mSzVB5iQXE7TrGbOXrLMJVFzMZS/POONejmpWC T5gW59050luRrEqbLwvI+BylaUQYrvR3VLtmFJA3nh6jSbsxL4D1Go1GdksAPFYJbqw2ahjm+JadN mti3QIyUpMGCLgT7AF3IA6MA+eLuhANszg8DTHjnbZ3hRkLBX4zIX8EjgP91iTVWFQeMI1tPfN68C SSt5EC44QCDJsGPVst6EMb6IEQfQE8ZGt7WnRlEpXq/mKKsPRzyCtKX2scI7NdfByocewFqeBNE1J 0Fjda3RvQ==; Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBfg-0007xT-6o for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 07:59:16 +0000 Received: by mail-pg1-x544.google.com with SMTP id v66-v6so6580546pgb.10 for ; Fri, 07 Sep 2018 00:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jeWHjhWZzqcn992r+CjxadoTg1glUklXZIt+KkbfGzY=; b=Iw6FIM/UTbLuebPjiA4jQVIGzj1ZOSMVexZ11oWFVNDZ/ufvkYBdyX+BbPZ/5aYKuB r7XPHSCEgPMikmy/gv+Bo0F7HsfeRIQE/WRc+OOPgtR5GjEeC+1fc0e67z4kIxqGHvFI 9s44tc/wjbhJiYdjVD0GmiWIk9iV8rl4OPZWo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jeWHjhWZzqcn992r+CjxadoTg1glUklXZIt+KkbfGzY=; b=csf2JmrgZ/9AS6WKRnX24tuc3HgTeiZE/JRvq0uDYYFn+5cz1fMjli/umxrjCUcweH aQNhhLViwiAx1DU9jIMgzcylFKljJgZV6unrwdjgRZ7Kqc+kBoPYF6fZOpSWGl4+vh0A VGBxlXLU8BJBESRGuT/7fJGs930kr4TZUX348Eo7AJhFrVT+RfBA4XHCCHp0TRLwk9mi BHKdoU8GhxVsQ1BL28wA/yCtjychMt3Dvg3B2bRmIwCuo8foVNu3GASgtJ8wnAaxy5hp PLcL4d72YrLFD8YGOoeVMkWEbw8dZxNJshPGgS4gzYe2tn6d/j3TU1hljF6nw/Lso6VF hZYw== X-Gm-Message-State: APzg51Dq0sP6/BovMdV/LALZGYmVM+1R7CBKZUbPJl0OAe3gnIOrvXNH PEHeEJFJZ2e6t7F4XiaWHhaeYQ== X-Google-Smtp-Source: ANB0VdZrG69yj9ElBSyC2eZg1/EFcPXyz/rqBMU49wEU/gT4vQCwnzRYWUbh+3xhlWJ+NispINZ47A== X-Received: by 2002:a62:56d9:: with SMTP id h86-v6mr7152853pfj.229.1536307082476; Fri, 07 Sep 2018 00:58:02 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l185-v6sm18675979pga.5.2018.09.07.00.58.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:58:01 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Fri, 7 Sep 2018 16:56:42 +0900 Message-Id: <20180907075653.4696-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_035916_308583_E0372B73 X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In kdump case, there exists only one dedicated memblock region as usable memory (crashk_res). With this patch, kexec_walk_memblock() runs a given callback function on this region. Cosmetic change: 0 to MEMBLOCK_NONE at for_each_free_mem_range*() Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- kernel/kexec_file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 370d7eab49fe..2f615a7968dd 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -511,8 +511,11 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, phys_addr_t mstart, mend; struct resource res = { }; + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, MEMBLOCK_NONE, &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the @@ -526,8 +529,8 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, break; } } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { + for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, + &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the * range while in kexec, end points to the last byte From patchwork Fri Sep 7 08:00:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591845 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 1E2D2112B for ; Fri, 7 Sep 2018 08:08:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DAE42ADAD for ; Fri, 7 Sep 2018 08:08:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3E582ADAF; Fri, 7 Sep 2018 08:08:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 66FD32ADAD for ; Fri, 7 Sep 2018 08:08:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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:In-Reply-To: References:List-Owner; bh=tN0gurgTYYIOOxH28IBUP7XW9uh2gakNvbzpDo0Cvxw=; b=hdd 4gPxSuO37EXCVNa+0DjBStdOkX41tO2McsTiSlQxr2t8alEich+7XXgozWTrVuVuILDiWAR7W5GTj xK12wWOd5p2pNMtGkPtjwulvjXLBnef7cS4UFuNRelGL0jbL+kOQIJ2vVBf+Ex5t/0Fiw4C0Rcm8n MFMWmUYCJpVcupt8F7yv3NdHHBsMBwfINvflfJHRHbvYksxxPr/72ZX3lTITXbrLi2iUQLzussTY4 sihVYVpikUQqy1Wz2UzKN2/gJ9h92X67ac6wMUK7hm8IN21lOf56u5g/fFEbvMEEzYXbPBmzmsMs2 RtcVE/JnpprjHIf5F9+C9ZSXkMRRJvA==; 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 1fyBo8-0006V1-9k; Fri, 07 Sep 2018 08:08:00 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBhg-0002tY-AN for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:01:28 +0000 Received: by mail-pg1-f196.google.com with SMTP id i190-v6so6602329pgc.6 for ; Fri, 07 Sep 2018 01:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=qys+w+KuRNMCFxzjw+1VloWOF/kuhazsT8XZwPi30r4=; b=c4/XB92kJZtTwM5QcIUvrwIc4hwABVpAL6FxknVxyVOPo1m7DFgHA45DOwP7MNdC4f 4++H0GZ8HMGKt/vb64/ye7yqQqgd4CiWLEzoPnE/dykm8dKrH7LJ5wHQ1cvvT6wKZ3pT DgW5JTw45FW5Ko3+dw+4v4HwWeRsrzB67UgfI= 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; bh=qys+w+KuRNMCFxzjw+1VloWOF/kuhazsT8XZwPi30r4=; b=bkqHRFb73odywQO7eXq17SU0cgzj0+dVoPoyj6UM/iZGGnrQ6mWZb2ku2F/1NAoVkk WjfqEuETGcCLOMdQvSVtnuSukyzVVas3+OSanFav3//M67MXETNWZPS9HAvhA3BEViIT 0h9+14apyIE2bsMIqrTdukMlVRMCiPr2oA2/k1xZ7OfjncYNYuycKfETla0kYRLuoXhF mutXBejD/4zNLE4Tr/+cLya02Txrm73vznFCWow+EvGTrNHbSEU2P5Y+NgjD1kTTE2E0 chI5kEXODj6V9xZa35LsMgst7MxCOpccbpgdgK4TlEiEsTPcSvudH+jRY5XlhElZBmnx 9Ttg== X-Gm-Message-State: APzg51DEvkh/ThS5vIhcUNA61fLbXOGXUYHIw5bb45YMI+cbFL0qM59N iqWOvXl4t4mTVN21lzfQQfUs9Q== X-Google-Smtp-Source: ANB0Vdalnqdia43nHeigB1OorGdg+H2T2Ip081oOMPcfExUY9Uqv5MtzXs2KUkW13+ZqCzDeeWQUpQ== X-Received: by 2002:a63:2d05:: with SMTP id t5-v6mr6916294pgt.403.1536307209430; Fri, 07 Sep 2018 01:00:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y7-v6sm8794078pge.8.2018.09.07.01.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:08 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 06/16] of/fdt: add helper functions for handling properties Date: Fri, 7 Sep 2018 17:00:30 +0900 Message-Id: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010120_507559_576A6424 X-CRM114-Status: GOOD ( 12.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , Rob Herring , james.morse@arm.com, Frank Rowand , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP These functions will be used later to handle kexec-specific properties in arm64's kexec_file implementation. Signed-off-by: AKASHI Takahiro Cc: Rob Herring Cc: Frank Rowand --- drivers/of/fdt.c | 62 ++++++++++++++++++++++++++++++++++++++++-- include/linux/of_fdt.h | 10 +++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 800ad252cf9c..dc960cea1355 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -25,6 +25,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -537,8 +538,8 @@ void *of_fdt_unflatten_tree(const unsigned long *blob, EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); /* Everything below here references initial_boot_params directly. */ -int __initdata dt_root_addr_cells; -int __initdata dt_root_size_cells; +int dt_root_addr_cells; +int dt_root_size_cells; void *initial_boot_params; @@ -1323,3 +1324,60 @@ late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ + +bool of_fdt_cells_size_fitted(u64 base, u64 size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((dt_root_addr_cells == 1) && (base > U32_MAX)) + return false; + + if ((dt_root_size_cells == 1) && (size > U32_MAX)) + return false; + + return true; +} + +size_t of_fdt_reg_cells_size(void) +{ + return (dt_root_addr_cells + dt_root_size_cells) * sizeof(u32); +} + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + __be32 val32; + + while (cells) { + val32 = cpu_to_fdt32((val64 >> (32 * (--cells))) & U32_MAX); + memcpy(buf, &val32, sizeof(val32)); + buf += sizeof(val32); + } +} + +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size) +{ + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + buf_size = of_fdt_reg_cells_size(); + prop = buf; + + fill_property(prop, addr, dt_root_addr_cells); + prop += dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, dt_root_size_cells); + + return fdt_setprop(fdt, nodeoffset, name, buf, buf_size); +} diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index b9cd9ebdf9b9..9615d6142578 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -37,8 +37,8 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node **mynodes); /* TBD: Temporary export of fdt globals - remove when code fully merged */ -extern int __initdata dt_root_addr_cells; -extern int __initdata dt_root_size_cells; +extern int dt_root_addr_cells; +extern int dt_root_size_cells; extern void *initial_boot_params; extern char __dtb_start[]; @@ -108,5 +108,11 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +bool of_fdt_cells_size_fitted(u64 base, u64 size); +size_t of_fdt_reg_cells_size(void); +int fdt_prop_len(const char *prop_name, int len); +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size); + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_OF_FDT_H */ From patchwork Fri Sep 7 08:00:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591853 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 DC86B5A4 for ; Fri, 7 Sep 2018 08:09:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCDFA2ADDE for ; Fri, 7 Sep 2018 08:09:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF4112ADF0; Fri, 7 Sep 2018 08:09:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48CDB2ADDE for ; Fri, 7 Sep 2018 08:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=M7HskRhvb7uKpaPyMVCFD+L3cPLioPqtP9kERY641aE=; b=G6LBB3bHymLyQdt6VFqvG3YceY DaeAp+K0ydq9XF5Ax2BNjiMXdpdkE+VfHCBxlxyNl+9pTiWIMtakTx3PrFr52LR8ec/HwXsDEBkhT qPa7c2u+DL/uDdiS7p7VOPXx9P51vaNU8e75PbCnHn2noGF/KeY0fKJ5bzuGAlOqhtUEJwgS6hD+/ y1+Exz5UOKrqh5lSV8+UJMmZy4+79ApGiZlLEgKpyBCySd9/GvCWEoF9zu1uhekTX7vQiUcy7747O MoiJeY2LTaWJuyBlbrflSOtphXn8hnRZqggoZccajEddmpvEsgxptrvwOhC3vintvJz1y3Oe0Atzi K63P73Kg==; 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 1fyBpS-00072Q-EN; Fri, 07 Sep 2018 08:09:22 +0000 Received: from mail-pg1-f194.google.com ([209.85.215.194]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBhw-000312-3X for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:01:40 +0000 Received: by mail-pg1-f194.google.com with SMTP id v66-v6so6583778pgb.10 for ; Fri, 07 Sep 2018 01:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=Opb8rBToQcMZtyPYTVhVnP0kWL6jOjIeziL6TJJFv1WBRD57nZtKirw3Gv+BigdMUA IfnfHFH2jGHiprpQONf+LFBgWyM0iAdDGxdcgKTFHBWR1yJofCRZVngza0NB4IdIuVsN YatTiRLRgRL3dzahQVtG+E4EKQTPVuN5XgPMM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=U9gR03/CbUqtkfu2hVw5tx9qL28QdtsCqUYWaX1niUKkMeTKF93gY17y+46YFQXz5K 1QsNe5WyLVOxYQ4hKr6vMY+NHekpuhuMFNiPxYQn3dlTSpFMy8j1vMwlAYEBTj6S47GK P4VLhyStr6ukrTlCAy+sZq3tXt8bGCWh+cXVlCZ9oUUew1ekYj5i4YRVYJw+MgW6LWhY HVi7iCcoNBlneROLGCqJ1/H1YkPEOfGMd6GW80A1SQnXlJu2I3u9N2Udwm6//l/9oYz/ yNyCpJiTK+isuBe0+92SNj5C6Mio3Me8AnZwFeUEiA/gDj0rucIMW0RBOJS7QeRo4+Li +QFw== X-Gm-Message-State: APzg51BazdqfB7uINQf85O3Aq897IDyKLf7ke6lMZGJS6/nKdDKWbr9P JgzYrcsOcwcIKhq+HrtLZP3Iew== X-Google-Smtp-Source: ANB0VdZ7w/sDOgYgYrqbJwijOoX5johxlrWvhDHbfMyxIOLJzpa5P+M+GD0CUDm/69cD2d43Hic2KA== X-Received: by 2002:a62:ed5:: with SMTP id 82-v6mr7109449pfo.198.1536307224906; Fri, 07 Sep 2018 01:00:24 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o10-v6sm7788864pgp.70.2018.09.07.01.00.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:24 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 07/16] arm64: add image head flag definitions Date: Fri, 7 Sep 2018 17:00:31 +0900 Message-Id: <20180907080040.4967-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010136_176057_6581925E X-CRM114-Status: GOOD ( 12.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Those image head's flags will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Acked-by: James Morse --- arch/arm64/include/asm/boot.h | 15 +++++++++++++++ arch/arm64/kernel/head.S | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/boot.h b/arch/arm64/include/asm/boot.h index 355e552a9175..0bab7eed3012 100644 --- a/arch/arm64/include/asm/boot.h +++ b/arch/arm64/include/asm/boot.h @@ -5,6 +5,21 @@ #include +#define ARM64_MAGIC "ARM\x64" + +#define HEAD_FLAG_BE_SHIFT 0 +#define HEAD_FLAG_PAGE_SIZE_SHIFT 1 +#define HEAD_FLAG_BE_MASK 0x1 +#define HEAD_FLAG_PAGE_SIZE_MASK 0x3 + +#define HEAD_FLAG_BE 1 +#define HEAD_FLAG_PAGE_SIZE_4K 1 +#define HEAD_FLAG_PAGE_SIZE_16K 2 +#define HEAD_FLAG_PAGE_SIZE_64K 3 + +#define head_flag_field(flags, field) \ + (((flags) >> field##_SHIFT) & field##_MASK) + /* * arm64 requires the DTB to be 8 byte aligned and * not exceed 2MB in size. diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index b0853069702f..8cbac6232ed1 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -91,7 +91,7 @@ _head: .quad 0 // reserved .quad 0 // reserved .quad 0 // reserved - .ascii "ARM\x64" // Magic number + .ascii ARM64_MAGIC // Magic number #ifdef CONFIG_EFI .long pe_header - _head // Offset to the PE header. From patchwork Fri Sep 7 08:00:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591859 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 E1560112B for ; Fri, 7 Sep 2018 08:10:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2F812ADF2 for ; Fri, 7 Sep 2018 08:10:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C689A2AE02; Fri, 7 Sep 2018 08:10:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D55F2ADF2 for ; Fri, 7 Sep 2018 08:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=AH82xejSFq8HIgX/nWs4sY6xm75sFioCSxYC3DPXxNg=; b=e+l9yAuItrC2Ai9Ly5WbbfqcO/ 1Jz+966uiOrci0nRuod/rLzrKr12dK9atF2AFxWObBEkKeSCdP7VyAuzMHGnHi2K3z6sD1yrIJTaf GSGbPxcGFLPgo5LWRkxxWIgs64P1gDJwTdwwDlS3cPy6nN5IfCWuJ+0c2sCXRHCivvsfMx5T0P9+T cDQG9YdW43fGAxcdFttgpqxlrHQffORMxH7FpWQcrcLUf0TRDuogV2DTGiULyLjxc5oTXlDbYjKb/ SHSXsXESs2fYGjxV5F9l9bex35Dxw9cgHMl5XnS21fZ0We9Zw+Br6tyDsCKIDXvDujbBmBKcmZYxZ 5fC/yBcA==; 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 1fyBqb-0000Ej-HD; Fri, 07 Sep 2018 08:10:33 +0000 Received: from mail-pl1-f195.google.com ([209.85.214.195]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBi7-00034J-HL for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:02:02 +0000 Received: by mail-pl1-f195.google.com with SMTP id b12-v6so6225472plr.8 for ; Fri, 07 Sep 2018 01:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=TmH1QzWEdjIScRitGPZDxo0kRunrfKh346dMTCHgL4WemhLrgJXrLlzBjN+nCXAuWy gCDKxLM8kTmf+MYRZA461r8JZjKI8C0b8KAyNi4UI++fnhOpsvPUJRFcCrtn0F4l/PIG ASgLni1wy+APVrPqon048Ll4ug/DU23G3WwCM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=roUJ2Gt/27uF6qneygfebpPYVa7SP0Ue0j8YElB0Inw1c5+nUEWOA+DaAmq1ELUdrG ekUdARkKEHwWcpCdL+zCnDKujtk7fP17bwdBt3gEWIPKF5wGLFSUCUzWFQe9j+8vfCi5 FzigZbk9kU8lLRzm8JBwItOKwSNY0tVe8sYsahPmxErp4JTUOH9BYw1hWc0som+eD3Zo IfSs4da+cDPiSkK89Nl9kZl9yfMl288VrehA3/ypHBNRvNSJlKbMvc/rQ2evBwzfnRX0 Oxrn8XgKzn+h25GAkluqGkZ5hoAEMbpRy/6GYD/ic4gWVRe4gGIqt9j/wIaHay/2YbsC nu1g== X-Gm-Message-State: APzg51CzLJWEQK/h2kDK0roaq4OtfkYxgkeaNDH6Cir9zqJlojAYAtdQ jMl0y8yqpAyWI2qLM2+Jukvq3w== X-Google-Smtp-Source: ANB0VdYrAtp/gUvBjI51R0qykIAQ4AyDo0qnXD2cJ9g2XlC7ham5sVbvn6vedeNBgwLYArGHpqXuGw== X-Received: by 2002:a17:902:20c6:: with SMTP id v6-v6mr6826590plg.228.1536307234715; Fri, 07 Sep 2018 01:00:34 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d19-v6sm12812464pgi.50.2018.09.07.01.00.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:34 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Fri, 7 Sep 2018 17:00:32 +0900 Message-Id: <20180907080040.4967-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010147_634667_C4E8FB32 X-CRM114-Status: GOOD ( 10.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Those helper functions for MMFR0 register will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/cpufeature.h | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 1717ba1db35d..cd90b5252d6d 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -486,11 +486,59 @@ static inline bool system_supports_32bit_el0(void) return cpus_have_const_cap(ARM64_HAS_32BIT_EL0); } +static inline bool system_supports_4kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN4_SHIFT); + + return val == ID_AA64MMFR0_TGRAN4_SUPPORTED; +} + +static inline bool system_supports_64kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN64_SHIFT); + + return val == ID_AA64MMFR0_TGRAN64_SUPPORTED; +} + +static inline bool system_supports_16kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN16_SHIFT); + + return val == ID_AA64MMFR0_TGRAN16_SUPPORTED; +} + static inline bool system_supports_mixed_endian_el0(void) { return id_aa64mmfr0_mixed_endian_el0(read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1)); } +static inline bool system_supports_mixed_endian(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_BIGENDEL_SHIFT); + + return val == 0x1; +} + static inline bool system_supports_fpsimd(void) { return !cpus_have_const_cap(ARM64_HAS_NO_FPSIMD); From patchwork Fri Sep 7 08:00:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591861 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 D51D95A4 for ; Fri, 7 Sep 2018 08:11:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C56532AE08 for ; Fri, 7 Sep 2018 08:11:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B75C82AE10; Fri, 7 Sep 2018 08:11:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 249C82AE08 for ; Fri, 7 Sep 2018 08:11:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=t/m+3VDl30qm+GDL5rHctMHFg32Vs6yrN0L9UWn+fCE=; b=mU0MW4SrsQRDLAV2ymczOXzCPL Yrb9ss/ipPNVdERzxupyziO+WUwEO7vhuRCBCFYX+aZSAG6/o2PM2uJCtV8eaJngkEsE7c8kBDUMN Ux4HNnqV9y6Xk7TEH6UglUH771/cb0FuTHnPNb02HS2Ovx9mw579DT+Q3x1NiKlI+qEolR3awf/A7 gi1Ayg7VbcwGz6HM40JwozyNfRWHpVWHL+JCP5s2EbBVKz7su/YADlXgTF0GIdEDE2FMM6GNPTY4I XuA7mBs+LQsmcP6kVerO/tvVk4lyqn4FUkiIDCJKrF2SWXjaMoHwa1ZYbli2jvPiSjo+D0zbleGOj j2BscEdQ==; 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 1fyBrO-0000hg-Sz; Fri, 07 Sep 2018 08:11:22 +0000 Received: from mail-pl1-f195.google.com ([209.85.214.195]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBi7-000389-HL for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:02:04 +0000 Received: by mail-pl1-f195.google.com with SMTP id b12-v6so6225694plr.8 for ; Fri, 07 Sep 2018 01:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Wek53x727l+CC28Me3kZmv40INMNgym0MEOVv8aRsME=; b=aMLoGtcKbZtYcDTYknTxqNRmjzsz5TmpU8UWKlGEgq3ouS/mEmCdeUyli8+9dThfXm 331KELwilkTkuU7ES4+trm/OnppENYt26MmHYfI5U7PogvC7XuwianlCKX3lWU4pV42N hI0QmcAvNmIyFcxP0XBOj904YNTV9anFCZLtg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Wek53x727l+CC28Me3kZmv40INMNgym0MEOVv8aRsME=; b=ZKa36Wl3e6zQe1bAeIEcQBx2efoKAJZkGqgs817JXGTnaZ0mS+/tmdVDURrdV64x4I pP7xjw/MYTbdFQtVE1PAoXnaqWZZYQ0A1zpnXZxd72q0KquG2HJGfrqvTOgjkjIU7TOw Xm9JNMOwqjX2bGi281TNXOEjP2dJy9gbhsA+fTU+12UXwAa7ikYWqudv6Ov/7q81Onza KFzYfJh+TGBUDlVa42ptADn4hIpvLB3pcauF1HnWzEIvXZCVAbKMjtD9fGyW5HByupiP FjViQP2K3wqp82mxWxU40zG1NuS+Ob4UZ/isP7jmogjIzM1ZSZp6rjFin4zLSTWKalR8 iVyw== X-Gm-Message-State: APzg51DDaz8nzlenJcOs5R1xdmOdHpPv//LJD+h12MD9/H1idzslH795 0yp80fCKKoa/dYvxYyqLX+CQDA== X-Google-Smtp-Source: ANB0VdaRLGOkhgdwdx5ZA853bM5ec5di05hYI5NIQX3kC/Mh1tlPBlsWe2J1CgjYl0U5po8U+DxUUA== X-Received: by 2002:a17:902:464:: with SMTP id 91-v6mr6757431ple.125.1536307243989; Fri, 07 Sep 2018 01:00:43 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f6-v6sm9369907pgf.52.2018.09.07.01.00.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:43 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 09/16] arm64: enable KEXEC_FILE config Date: Fri, 7 Sep 2018 17:00:33 +0900 Message-Id: <20180907080040.4967-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010147_649625_A229013A X-CRM114-Status: GOOD ( 14.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Modify arm64/Kconfig to enable kexec_file_load support. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Acked-by: James Morse --- arch/arm64/Kconfig | 9 +++++++++ arch/arm64/kernel/Makefile | 3 ++- arch/arm64/kernel/machine_kexec_file.c | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/machine_kexec_file.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1b1a0e95c751..5eb18d0cb513 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -843,6 +843,15 @@ config KEXEC but it is independent of the system firmware. And like a reboot you can start any kernel with it, not just Linux. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + help + This is new version of kexec system call. This system call is + file based and takes file descriptors as system call argument + for kernel and initramfs as opposed to list of segments as + accepted by previous system call. + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 95ac7374d723..8f1326b2d327 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -49,8 +49,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..c38a8048ed00 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; From patchwork Fri Sep 7 08:00:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591865 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 5A3425A4 for ; Fri, 7 Sep 2018 08:12:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BF1E2AE08 for ; Fri, 7 Sep 2018 08:12:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4048E2AE10; Fri, 7 Sep 2018 08:12:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6F2792AE08 for ; Fri, 7 Sep 2018 08:12: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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=IMICTPrAm4ba1ADECrLPDPQFaCNNet/OWlCyEyD+uCg=; b=P3nF6gObj3g69DWXSyBkdBYESm iKcdyQ22i+xhODKKtJDpF2Um4936C/4fAR4I8EAM7jqYkjVNiQ3aOhkEAg8+T24uk91noXCH9eDGC vyjHs94+5L9yHkacsJqpoeW7bMKTEIrFh8N2Zpo0+SkrORBPEc0iZk/qJxSozMRdrlVP25FdlVhtw SkgVe1aQjFFjL8452XmHfQzocjJ2sqryYM2VSsbjLTi20pMA3AZCE5a6B1AHaPsHO7Au4oTT7vw5h ENdXgnf0OKJuGZ9Sm/tSR3d3DODiTEoQGkdsvr28edYBip9w37eQnRVtOF2U+8u2QnH/sTC6z/0ZE Irq+L0hw==; 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 1fyBsJ-00015h-Lk; Fri, 07 Sep 2018 08:12:19 +0000 Received: from mail-pl1-f195.google.com ([209.85.214.195]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBiO-0003Bs-0q for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:02:22 +0000 Received: by mail-pl1-f195.google.com with SMTP id f6-v6so6245838plo.1 for ; Fri, 07 Sep 2018 01:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=MZ9A3QxJ7yRFgCIEoDFMglvR9MFB25h+UXHZBcN7/UOYpmmUXgi1mSCgTP+t/wweU0 zwdH74SMalwuKNMY0AKwCfQ5f1pJS+9JZj7BJZoARJLLUyk5aTxJjMD6xisomeA4BNng aKJBLMbfPRiLXNAnDCTTDLTUryjVXLq/w4MEI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=oP8R/Io3dk4AHJ946/ePOjA3Kq8uF1RrMLQbiKFpN2XRuLacbU2NiZ9/a5K89BMuHe nr9ME1dSJorv9rQZRDDs/dEZP/JbOb9BDXk7s1XAyAR/4VLN03FQBkSlykDUzRJW9q/j 6ZFNXxW0Irmk9qKCZzwWaJm4kq1V75BN6nZJ4NlM59bMJTervygmzSJelvbFTJOKje+2 R6/A3KPdDw9UDsjzmruYCQ2iZG0CId1Ox9rdPj4XI8weZT7Optwk80S/G9+0pe/c7sUX 3vJKhUglpfpD0wh81OLZvB22RyTX0sYU/sIb7P0Dv+d6WFOe5ZNzsop0QLC+WMYZmHei seXA== X-Gm-Message-State: APzg51Bcv/+nWuKlMCigxBk+dbVo1lbRdmyIGJYIqI05e16btnMFUwpl ZQstNV8iv+gYDN1GD1aEt0tbnQ== X-Google-Smtp-Source: ANB0VdZ4Ph6XxIz7yk79prCPqeUXuq1u+ajtrHhpG1RtU4zn6SjbTbmNVm0JlVhrRYwwT0o2Jm2rtg== X-Received: by 2002:a17:902:3c5:: with SMTP id d63-v6mr6654075pld.145.1536307253444; Fri, 07 Sep 2018 01:00:53 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d12-v6sm10819689pfk.69.2018.09.07.01.00.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:52 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 10/16] arm64: kexec_file: load initrd and device-tree Date: Fri, 7 Sep 2018 17:00:34 +0900 Message-Id: <20180907080040.4967-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010204_118986_6FAEA53F X-CRM114-Status: GOOD ( 16.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 MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP load_other_segments() is expected to allocate and place all the necessary memory segments other than kernel, including initrd and device-tree blob (and elf core header for crash). While most of the code was borrowed from kexec-tools' counterpart, users may not be allowed to specify dtb explicitly, instead, the dtb presented by the original boot loader is reused. arch_kimage_kernel_post_load_cleanup() is responsible for freeing arm64- specific data allocated in load_other_segments(). Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 17 +++ arch/arm64/kernel/machine_kexec_file.c | 188 +++++++++++++++++++++++++ 2 files changed, 205 insertions(+) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..157b2897d911 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,23 @@ static inline void crash_prepare_suspend(void) {} static inline void crash_post_resume(void) {} #endif +#ifdef CONFIG_KEXEC_FILE +#define ARCH_HAS_KIMAGE_ARCH + +struct kimage_arch { + void *dtb; + unsigned long dtb_mem; +}; + +struct kimage; + +extern int arch_kimage_file_post_load_cleanup(struct kimage *image); +extern int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index c38a8048ed00..f53f14bd1700 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,200 @@ * Copyright (C) 2018 Linaro Limited * Author: AKASHI Takahiro * + * Most code is derived from arm64 port of kexec-tools */ #define pr_fmt(fmt) "kexec_file: " fmt +#include +#include #include +#include +#include +#include +#include +#include + +/* relevant device tree properties */ +#define FDT_PSTR_INITRD_STA "linux,initrd-start" +#define FDT_PSTR_INITRD_END "linux,initrd-end" +#define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { NULL }; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb); + image->arch.dtb = NULL; + + return kexec_image_post_load_cleanup_default(image); +} + +static int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + void **dtb_buf, unsigned long *dtb_buf_len) +{ + void *buf = NULL; + size_t buf_size; + int nodeoffset; + int ret; + + /* duplicate dt blob */ + buf_size = fdt_totalsize(initial_boot_params); + + if (initrd_load_addr) { + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len(FDT_PSTR_INITRD_STA, sizeof(u64)); + buf_size += fdt_prop_len(FDT_PSTR_INITRD_END, sizeof(u64)); + } + + if (cmdline) + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len(FDT_PSTR_BOOTARGS, cmdline_len); + + buf = vmalloc(buf_size); + if (!buf) { + ret = -ENOMEM; + goto out_err; + } + + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + nodeoffset = fdt_path_offset(buf, "/chosen"); + if (nodeoffset < 0) { + ret = -EINVAL; + goto out_err; + } + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop_string(buf, nodeoffset, FDT_PSTR_BOOTARGS, + cmdline); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_BOOTARGS); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_INITRD_STA, + initrd_load_addr); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_INITRD_END, + initrd_load_addr + initrd_len); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_INITRD_STA); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_INITRD_END); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* trim a buffer */ + fdt_pack(buf); + *dtb_buf = buf; + *dtb_buf_len = fdt_totalsize(buf); + + return 0; + +out_err: + vfree(buf); + return ret; +} + +int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + void *dtb = NULL; + unsigned long initrd_load_addr = 0, dtb_len; + int ret = 0; + + kbuf.image = image; + /* not allocate anything below the kernel */ + kbuf.buf_min = kernel_load_addr + kernel_size; + + /* load initrd */ + if (initrd) { + kbuf.buffer = initrd; + kbuf.bufsz = initrd_len; + kbuf.mem = 0; + kbuf.memsz = initrd_len; + kbuf.buf_align = 0; + /* within 1GB-aligned window of up to 32GB in size */ + kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + + (unsigned long)SZ_1G * 32; + kbuf.top_down = false; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + initrd_load_addr = kbuf.mem; + + pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + initrd_load_addr, initrd_len, initrd_len); + } + + /* load dtb blob */ + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, cmdline_len, &dtb, &dtb_len); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + kbuf.buffer = dtb; + kbuf.bufsz = dtb_len; + kbuf.mem = 0; + kbuf.memsz = dtb_len; + /* not across 2MB boundary */ + kbuf.buf_align = SZ_2M; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + image->arch.dtb = dtb; + image->arch.dtb_mem = kbuf.mem; + + pr_debug("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kbuf.mem, dtb_len, dtb_len); + + return 0; + +out_err: + vfree(dtb); + return ret; +} From patchwork Fri Sep 7 08:00:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591871 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 E117A5A4 for ; Fri, 7 Sep 2018 08:14:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1B7528825 for ; Fri, 7 Sep 2018 08:14:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C59162A550; Fri, 7 Sep 2018 08:14:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 08F1828825 for ; Fri, 7 Sep 2018 08:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3mGOOxFW939CeyXJdxaLaxiZboU58JkpkgqkZOx8Sus=; b=SR2JA6/V1sVzCWyytLEX2M/Ct+ GN2h8FmsCl8B/YZu+jnEMDALKcX5ordRF2rAzicilT7ZyvT2hRT14pa1qNR9RO+3BDzF2hTdtE8RG Jx77+6E0JgdseDTztBTxlfvWREKcIlVTsBM39CqtHhf2OA2LvVoUrYnsgrLQ+cGgPUjeYgyuZJGA1 Y+CCrbJvWkD7d74RYoDfi5SzlVXF9VQKo2cF0k5j2k+rgm4nyLQUsk18/I/1WY3m4rzI+yYBawl89 7InFr+PrsL30NKFv/tUlfcwq/Ki5JSnSL5maz+0lScPP+GKc2FKsSktkVYDh4HSzSD6CZN8QwCMhV n1b5hNOQ==; 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 1fyBtn-0001jV-BL; Fri, 07 Sep 2018 08:13:51 +0000 Received: from mail-pg1-f196.google.com ([209.85.215.196]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBib-0003EX-He for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:02:37 +0000 Received: by mail-pg1-f196.google.com with SMTP id d1-v6so6610534pgo.3 for ; Fri, 07 Sep 2018 01:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=cCvWfWiPrepkCS1NeuS+dm7T4KZLOOTVOQ9PbY1I/rAycwyxcyjhvq7fdTPlnql/Uj tYtRa2vSQq3G1DDOWuXI+H92QtlIflCSgQTif37ykruNXrmX9DGKMFQ3s8pGvMgQ5SOI W0SeDvIQNkB05GH/M5apTpH1wacLOPVuVGYFQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=H55WCyKJDJTyVY0dtgxhrj6zscXQ89y7Vw7Xij2qN9oKczo2LyUOnnWz6QK6wwJ2Ji Me78eeoHsD1Qgw+e5L3dkM2rDF4CFnchobpp0vrXmCoiO1U0tZD/rwPU1Ps4VrbwlAkx pNySXE8kq+sF8O7FAFFi/i1PwDeVcwerWbmbUwnkUQc/zDqOMGFQZGB1U4R3A7+AM4DU +Ha7qjBszRcSv1xGGS92nuM9Vs1f+6iX79A2GDOO+OTmjcnY98GPNCtIpIF5e7wqfYhv FmsNGQXQNluxECAxvE+WgBfmcDzaWZbSbk/UTjJMvk7utRCV+waRhSsRbMOcs2CxCca+ hpfQ== X-Gm-Message-State: APzg51AjJWco9+UWbbBMpUVtLr655c6hKSRG+cn0oinmUzjnox7QPqGZ ZWt4W7cPgAHqGFUWUhKY5MCZzWmREbM= X-Google-Smtp-Source: ANB0VdYxIYhDsNPHtspJWlrJH8RDOE8Vq00j6jxB3kc7dFz1rNu+5bK25liSLeu0/BRXFHsthFM6OQ== X-Received: by 2002:a63:d343:: with SMTP id u3-v6mr6922649pgi.420.1536307267025; Fri, 07 Sep 2018 01:01:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r25-v6sm8762276pgm.59.2018.09.07.01.01.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:06 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Fri, 7 Sep 2018 17:00:35 +0900 Message-Id: <20180907080040.4967-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010217_616495_B57D84B4 X-CRM114-Status: GOOD ( 18.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 MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch provides kexec_file_ops for "Image"-format kernel. In this implementation, a binary is always loaded with a fixed offset identified in text_offset field of its header. Regarding signature verification for trusted boot, this patch doesn't contains CONFIG_KEXEC_VERIFY_SIG support, which is to be added later in this series, but file-attribute-based verification is still a viable option by enabling IMA security subsystem. You can sign(label) a to-be-kexec'ed kernel image on target file system with: $ evmctl ima_sign --key /path/to/private_key.pem Image On live system, you must have IMA enforced with, at least, the following security policy: "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig" See more details about IMA here: https://sourceforge.net/p/linux-ima/wiki/Home/ Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 28 +++++++ arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/kexec_image.c | 108 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 1 + 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/kexec_image.c diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 157b2897d911..5e673481b3a3 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -101,6 +101,34 @@ struct kimage_arch { unsigned long dtb_mem; }; +/** + * struct arm64_image_header - arm64 kernel image header + * See Documentation/arm64/booting.txt for details + * + * @mz_magic: DOS header magic number ('MZ', optional) + * @code1: Instruction (branch to stext) + * @text_offset: Image load offset + * @image_size: Effective image size + * @flags: Bit-field flags + * @reserved: Reserved + * @magic: Magic number + * @pe_header: Offset to PE COFF header (optional) + **/ + +struct arm64_image_header { + __le16 mz_magic; /* also code0 */ + __le16 pad; + __le32 code1; + __le64 text_offset; + __le64 image_size; + __le64 flags; + __le64 reserved[3]; + __le32 magic; + __le32 pe_header; +}; + +extern const struct kexec_file_ops kexec_image_ops; + struct kimage; extern int arch_kimage_file_post_load_cleanup(struct kimage *image); diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 8f1326b2d327..8cd514855eec 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -51,7 +51,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..d64f5e9f9d22 --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kexec image loader + + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + */ + +#define pr_fmt(fmt) "kexec_file(Image): " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int image_probe(const char *kernel_buf, unsigned long kernel_len) +{ + const struct arm64_image_header *h; + + h = (const struct arm64_image_header *)(kernel_buf); + + if (!h || (kernel_len < sizeof(*h)) || + memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) + return -EINVAL; + + return 0; +} + +static void *image_load(struct kimage *image, + char *kernel, unsigned long kernel_len, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct arm64_image_header *h; + u64 flags, value; + struct kexec_buf kbuf; + unsigned long text_offset; + struct kexec_segment *kernel_segment; + int ret; + + /* Don't support old kernel */ + h = (struct arm64_image_header *)kernel; + if (!h->text_offset) + return ERR_PTR(-EINVAL); + + /* Check cpu features */ + flags = le64_to_cpu(h->flags); + value = head_flag_field(flags, HEAD_FLAG_BE); + if (((value == HEAD_FLAG_BE) && !IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) || + ((value != HEAD_FLAG_BE) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))) + if (!system_supports_mixed_endian()) + return ERR_PTR(-EINVAL); + + value = head_flag_field(flags, HEAD_FLAG_PAGE_SIZE); + if (((value == HEAD_FLAG_PAGE_SIZE_4K) && + !system_supports_4kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_64K) && + !system_supports_64kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_16K) && + !system_supports_16kb_granule())) + return ERR_PTR(-EINVAL); + + /* Load the kernel */ + kbuf.image = image; + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = false; + + kbuf.buffer = kernel; + kbuf.bufsz = kernel_len; + kbuf.mem = 0; + kbuf.memsz = le64_to_cpu(h->image_size); + text_offset = le64_to_cpu(h->text_offset); + kbuf.buf_align = MIN_KIMG_ALIGN; + + /* Adjust kernel segment with TEXT_OFFSET */ + kbuf.memsz += text_offset; + + ret = kexec_add_buffer(&kbuf); + if (ret) + return ERR_PTR(ret); + + kernel_segment = &image->segment[image->nr_segments - 1]; + kernel_segment->mem += text_offset; + kernel_segment->memsz -= text_offset; + image->start = kernel_segment->mem; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kernel_segment->mem, kbuf.bufsz, + kernel_segment->memsz); + + /* Load additional data */ + ret = load_other_segments(image, + kernel_segment->mem, kernel_segment->memsz, + initrd, initrd_len, cmdline, cmdline_len); + + return ERR_PTR(ret); +} + +const struct kexec_file_ops kexec_image_ops = { + .probe = image_probe, + .load = image_load, +}; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index f53f14bd1700..05fb2d4e6fef 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -25,6 +25,7 @@ #define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Fri Sep 7 08:00:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591869 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 5FC47112B for ; Fri, 7 Sep 2018 08:13:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F1BB28479 for ; Fri, 7 Sep 2018 08:13:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40C5128585; Fri, 7 Sep 2018 08:13:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7BB4E28479 for ; Fri, 7 Sep 2018 08:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ddDYqYhkY2b4/OE/tYU2yLOEaPe7TL45CNYjveHsKKo=; b=imh/Bpyw47rpB4tfOYphiel71K sbvX7vtw1c5e4sm7hhWHTX02LF/LdaIbK6XaKEjUHML3vqhscHsiQjFg0DAOcojP1dytEhcSHPSoe bHgNhdngPGzLUSRZqjrk+IbeORDkoUI0ngQkLJi5ycCFOHv1iafBIZ8RbFWbpJBhD5uHcYJSqOjKv 0/jbQFWGpbSLXWywlUoaZCWiWtWK3OX6Uuk+B46NN7fb1HUygn7vChuLmvS0/bqBf1j21eWCz7/of nWPK7EAQ7pyM83VaneYop/OabZMDrX2AOR8GfXgp06RIobb27KK8nrVSZPrsjH1ZWuByXpvE2cCGu ioCb+eaQ==; 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 1fyBsv-0001Lb-1F; Fri, 07 Sep 2018 08:12:57 +0000 Received: from mail-pf1-f194.google.com ([209.85.210.194]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBib-0003FK-I3 for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:02:34 +0000 Received: by mail-pf1-f194.google.com with SMTP id p12-v6so6637317pfh.2 for ; Fri, 07 Sep 2018 01:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=TfbOiWS9heV3iy9bKjpBx5utWenk+HNyevEckxzOh1Da1c1e6NsmI/2Iv/5VrDEe1+ +Ci63eYbIj4xmAgxJ2/HliOUTtKtoqLHvlz/pnkAEkO5/7WwJpj1MwTmT1Gqw7aZKqbH hMwcKiLnQU311Hir4ZdnMA3tU6k8KIHwEVk7c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=coaI2wNzfkrGpDeK0pwRWmwKDGxfZoifXROLJWYxKLxXB0zd9CFc6Ml9TGJp+m9w9i YOcHQriCwVHetqEPhsXvDgIS77oajYFFmrsy5Dx9P2oHHX8mqv7UF7h93lOuyhOaW01v DQXb7GZFXjCe3OtGl5qlqawlZ10m8riCVf6cMaEiQoTgSo/fAgeat9jvWZGuq1L5urLq LhPOhj6uDVQZXdaW77NxOhxaj6FFnI0+w23gWMPpfbQG+SPE9PCSAGKk2ZHAOKzvyZKR gzw6piE2ppCWtsv34itxevG2bKcw6u78+P5ISGu2xGEzl9aPVTOi4LLMrZpP0aHO76aB E+UA== X-Gm-Message-State: APzg51COGATSdMP/DyXCqb2VVl+6uIL5TNt9N4ruu2F7LUL2iq0WEmnp Decx/P0cKJN86jkBV/3XITKbuw== X-Google-Smtp-Source: ANB0VdZmf1cdv/t6ndoxWTTxsHgs99fRH2hZ8GKFrzahvLgcuRR9yUHntMc2k3iifsFFUsbBkQ5wvw== X-Received: by 2002:a63:f44d:: with SMTP id p13-v6mr7072731pgk.257.1536307276719; Fri, 07 Sep 2018 01:01:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c20-v6sm18010130pfh.143.2018.09.07.01.01.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:15 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 12/16] arm64: kexec_file: add crash dump support Date: Fri, 7 Sep 2018 17:00:36 +0900 Message-Id: <20180907080040.4967-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010217_600718_30A37708 X-CRM114-Status: GOOD ( 20.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Enabling crash dump (kdump) includes * prepare contents of ELF header of a core dump file, /proc/vmcore, using crash_prepare_elf64_headers(), and * add two device tree properties, "linux,usable-memory-range" and "linux,elfcorehdr", which represent respectively a memory range to be used by crash dump kernel and the header's location Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 4 + arch/arm64/kernel/machine_kexec_file.c | 113 ++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 5e673481b3a3..1b2c27026ae0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -99,6 +99,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb; unsigned long dtb_mem; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_mem; + unsigned long elf_headers_sz; }; /** diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 05fb2d4e6fef..ecaecb122cad 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,10 +16,14 @@ #include #include #include +#include #include +#include #include /* relevant device tree properties */ +#define FDT_PSTR_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PSTR_MEM_RANGE "linux,usable-memory-range" #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" @@ -34,6 +38,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb); image->arch.dtb = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return kexec_image_post_load_cleanup_default(image); } @@ -43,12 +51,29 @@ static int setup_dtb(struct kimage *image, void **dtb_buf, unsigned long *dtb_buf_len) { void *buf = NULL; - size_t buf_size; + size_t buf_size, range_size; int nodeoffset; int ret; + /* check ranges against root's #address-cells and #size-cells */ + if (image->type == KEXEC_TYPE_CRASH && + (!of_fdt_cells_size_fitted(image->arch.elf_headers_mem, + image->arch.elf_headers_sz) || + !of_fdt_cells_size_fitted(crashk_res.start, + crashk_res.end - crashk_res.start + 1))) { + pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n"); + ret = -EINVAL; + goto out_err; + } + /* duplicate dt blob */ buf_size = fdt_totalsize(initial_boot_params); + range_size = of_fdt_reg_cells_size(); + + if (image->type == KEXEC_TYPE_CRASH) { + buf_size += fdt_prop_len(FDT_PSTR_KEXEC_ELFHDR, range_size); + buf_size += fdt_prop_len(FDT_PSTR_MEM_RANGE, range_size); + } if (initrd_load_addr) { /* can be redundant, but trimmed at the end */ @@ -78,6 +103,22 @@ static int setup_dtb(struct kimage *image, goto out_err; } + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(buf, nodeoffset, FDT_PSTR_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(buf, nodeoffset, FDT_PSTR_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(buf, nodeoffset, FDT_PSTR_BOOTARGS, @@ -135,6 +176,43 @@ static int setup_dtb(struct kimage *image, return ret; } +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + unsigned int nr_ranges; + int ret; + u64 i; + phys_addr_t start, end; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) + nr_ranges++; + + cmem = kmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL); + if (!cmem) + return -ENOMEM; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) { + cmem->ranges[cmem->nr_ranges].start = start; + cmem->ranges[cmem->nr_ranges].end = end - 1; + cmem->nr_ranges++; + } + + /* Exclude crashkernel region */ + ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + + if (!ret) + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -142,14 +220,43 @@ int load_other_segments(struct kimage *image, char *cmdline, unsigned long cmdline_len) { struct kexec_buf kbuf; - void *dtb = NULL; - unsigned long initrd_load_addr = 0, dtb_len; + void *headers, *dtb = NULL; + unsigned long headers_sz, initrd_load_addr = 0, dtb_len; int ret = 0; kbuf.image = image; /* not allocate anything below the kernel */ kbuf.buf_min = kernel_load_addr + kernel_size; + /* load elf core header */ + if (image->type == KEXEC_TYPE_CRASH) { + ret = prepare_elf_headers(&headers, &headers_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + goto out_err; + } + + kbuf.buffer = headers; + kbuf.bufsz = headers_sz; + kbuf.mem = 0; + kbuf.memsz = headers_sz; + kbuf.buf_align = SZ_64K; /* largest supported page size */ + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(headers); + goto out_err; + } + image->arch.elf_headers = headers; + image->arch.elf_headers_mem = kbuf.mem; + image->arch.elf_headers_sz = headers_sz; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_headers_mem, headers_sz, headers_sz); + } + /* load initrd */ if (initrd) { kbuf.buffer = initrd; From patchwork Fri Sep 7 08:00:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591873 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 E47EB5A4 for ; Fri, 7 Sep 2018 08:15:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D373D28825 for ; Fri, 7 Sep 2018 08:15:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C73E02A651; Fri, 7 Sep 2018 08:15: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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3831928825 for ; Fri, 7 Sep 2018 08:15: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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Yu1kp3ja0qZGv9b20TLYi2FgjBScBvweBt/6FjfzXA4=; b=fFu2OVSVlTxugrh/Psx1F9HgQR muJH7hSKsK5S1r4vmgyOK0ZYyzF1wy/YLH5y1sTN9P+flp2V9vCxxRPFpSk1C6zb86YSc1xyjGP+R 0bhq5ihIhEAHwgh+YbP6Pp0fN+kq+RGUb1fILbdEqVG8EQBOVwpsp+leGmGrV14TSdo1Nz4DeCfU/ Ntw8x3QeZuBiRN2YgLESeau0hWGyY11gx2gWcakySBt/xm/aHUek9POe2l40the4vVQHTi3MRbEdy W3A/4qafwxMCS9T9lBsII7Ne0ild6qzYHSrZM1w9LRLzwx4fhamXfe9GVoOYH1zMsD3Sl7hzpkVt1 r/tUsfIQ==; 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 1fyBvG-0002qS-MG; Fri, 07 Sep 2018 08:15:22 +0000 Received: from mail-pf1-f196.google.com ([209.85.210.196]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBiu-0003Gy-VW for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:02:41 +0000 Received: by mail-pf1-f196.google.com with SMTP id d4-v6so6645562pfn.0 for ; Fri, 07 Sep 2018 01:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=JNg4+qmPrhqL8pI8iQK66/MOP/PlN0U7kyxGs5tZ1O9HlEX1oOhHBvPqrkMp677Di6 WUCk3qUKzfoHWcnOlZ0FJKGvHlU5PrY9Sw4aklOpAAEO25wHy/OdoLz/qHzao1zzkR2Q JZDnMksWJ6LEm0z1w+idwhcItZMumFLDpBwDk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=ZPEp0eP/HHg3Skn+UiH59H8rBsBOn7nsGrBc0tLPSeQGlFuRWAAZjadBahpOpiYyVZ lffJgUdgteA85Jnz8q5FD2nk0WKJTAazFVpUxhxGPRzxaIPtRE6+k/qW+v+j8HcvQMGE Ot4qS7p0zPmPXhRAq2pfwUUNoqfIA31xODtZImxojW4YYLeSqYn+xiDMAF3zVX6k/z/P Il1rFaAN3dO5RhE4aJihdZu+gK6yr51zjUdU0k7IS3TDGwvEEnhmTTiYbITA2KqiuE0f XtxIDJpm+VMsn9j00Usk1tcEY0ewoclHWmwz18XY0fKoHtUgUcL3zSxP1TVHuUbahBVJ aEiQ== X-Gm-Message-State: APzg51BdYutYPy5yo1coq2Tz258TBD6J/SBjk4r8m0s40vIbEdnN2wFj sC/q7TdNRf3j/xW4DmQw9F5o+w== X-Google-Smtp-Source: ANB0VdYWH6QTEHzaqo/7NYbbA/kO9M7faSViB5a4L2+jBqbHvGl3w8gFnFb7JckudrVDOKBR1EoauA== X-Received: by 2002:a62:455b:: with SMTP id s88-v6mr7046964pfa.203.1536307286115; Fri, 07 Sep 2018 01:01:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x23-v6sm17566759pff.9.2018.09.07.01.01.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:25 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Fri, 7 Sep 2018 17:00:37 +0900 Message-Id: <20180907080040.4967-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010237_069764_E5015D10 X-CRM114-Status: GOOD ( 15.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On arm64, purgatory would do almost nothing. So just invoke secondary kernel directly by jumping into its entry code. While, in this case, cpu_soft_restart() must be called with dtb address in the fifth argument, the behavior still stays compatible with kexec_load case as long as the argument is null. Signed-off-by: AKASHI Takahiro Reviewed-by: James Morse Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/cpu-reset.S | 8 ++++---- arch/arm64/kernel/machine_kexec.c | 12 ++++++++++-- arch/arm64/kernel/relocate_kernel.S | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 8021b46c9743..a2be30275a73 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -22,11 +22,11 @@ * __cpu_soft_restart(el2_switch, entry, arg0, arg1, arg2) - Helper for * cpu_soft_restart. * - * @el2_switch: Flag to indicate a swich to EL2 is needed. + * @el2_switch: Flag to indicate a switch to EL2 is needed. * @entry: Location to jump to for soft reset. - * arg0: First argument passed to @entry. - * arg1: Second argument passed to @entry. - * arg2: Third argument passed to @entry. + * arg0: First argument passed to @entry. (relocation list) + * arg1: Second argument passed to @entry.(physical kernel entry) + * arg2: Third argument passed to @entry. (physical dtb address) * * Put the CPU into the same state as it would be if it had been reset, and * branch to what would be the reset vector. It must be executed with the diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index f6a5c6bc1434..c63c355e2f18 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -212,9 +212,17 @@ void machine_kexec(struct kimage *kimage) * uses physical addressing to relocate the new image to its final * position and transfers control to the image entry point when the * relocation is complete. + * In kexec case, kimage->start points to purgatory assuming that + * kernel entry and dtb address are embedded in purgatory by + * userspace (kexec-tools). + * In kexec_file case, the kernel starts directly without purgatory. */ - - cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, 0); + cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->arch.dtb_mem); +#else + 0); +#endif BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index f407e422a720..95fd94209aae 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,6 +32,7 @@ ENTRY(arm64_relocate_new_kernel) /* Setup the list loop variables. */ + mov x18, x2 /* x18 = dtb address */ mov x17, x1 /* x17 = kimage_start */ mov x16, x0 /* x16 = kimage_head */ raw_dcache_line_size x15, x0 /* x15 = dcache line size */ @@ -107,7 +108,7 @@ ENTRY(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, xzr + mov x0, x18 mov x1, xzr mov x2, xzr mov x3, xzr From patchwork Fri Sep 7 08:00:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591875 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 815D65A4 for ; Fri, 7 Sep 2018 08:16:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70C1028825 for ; Fri, 7 Sep 2018 08:16:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62A4F2A651; Fri, 7 Sep 2018 08:16:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C20D428825 for ; Fri, 7 Sep 2018 08:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=31FO+3YWw+lbgK7CbqFVgxHXdp66iMzrGJV9CRXr2OM=; b=hY28DkzKGjurpFtaYHiUaOXtAF sfmfYfSgcqfU08p0qc/RnEw2iboa+EvVc/MEW6fAn8FIUTfJYOJTJo+Q32mjEyQrNlAOx/f2bQhDN ewoYfA9oeWfUGCNljvG7opEKJDSPMpGqC1lud7M1P5p8X075HRcZx45vvNBxW9qNkgbY6WcfAfLaC tb/kcjp0NOTBTFwGoqkuzrUdI56hRi+A1u3t2gC6O1e0ecGxu1Z/pEn68HuiL6Ciy4njpRAHagbCL WAWSQ7+qq2Toe9U2lex8ycDqUSfQrnCdFUNCIex/LIw8mOdoXVp2KWc2ckj4aeVpNpkIWeMEI8nh9 4mx/6yXg==; 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 1fyBwS-00046m-Qm; Fri, 07 Sep 2018 08:16:36 +0000 Received: from mail-pl1-f196.google.com ([209.85.214.196]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBj4-0003Hq-Ql for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:02:53 +0000 Received: by mail-pl1-f196.google.com with SMTP id u11-v6so6232168plq.5 for ; Fri, 07 Sep 2018 01:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=JyzLWOrGqoQh8eFOMBUNRAUWVulDA6drih+fd8GjQIsmU3ep50Kcg2+k/Rp0wT1lc6 BwOLxrjdARBYQomVgaLzINl3jX/PhP8dso+o2a48YgTRkjUXOIfC7geUiJ8XDSjYfczY byVv4TTS5c6khfV1Lohapgo9TJ8wzjfsKZ4mE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=YdJTUqiGGOiXEG3PNWwFMSgO/ECfKztRMuYClZCZzaPtSTF2VOgxaolJlGRregrAKz BNvdPry9dHDu9/Fd6JiRdwOyPpQMDXWoIy0+O0V1FSX75X+9giOFVKUFK2Cx0CFmorcZ 5jrbOG3Wodjh/JRNrfFzdz4nUNGeY7K3SNuWT0dJ98OIbo0K+dh7//pf2rlVYGK7ZRMR fm8uHxabSCsErAfNIqYCL+ccIOrphiOsz4TGDfqcn0FVbY+pIugaGJdvGJJYb56uMjDS amTEZi/iiMrswZ9uO9yykcrPOYSF0p51NxAF7z2YkQBWO1jCUdeGtz5gY4Bj+1bMRjXq RQkQ== X-Gm-Message-State: APzg51AgdcUEsAY14wKNTgSqTtbqVnmbHO2HKLbPRTpMGsUUnTCOb7vS rx3SDIW0o3nabsOarCuZjfi04Q== X-Google-Smtp-Source: ANB0VdZFg50Kt25YW660rtBie1bJyJfVIA7pQFzqusIqxeZeKzbgjgKArmCDyC03/n1E+QIoHbBeGA== X-Received: by 2002:a17:902:c6:: with SMTP id a64-v6mr6713497pla.180.1536307296340; Fri, 07 Sep 2018 01:01:36 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b14-v6sm10811236pfc.178.2018.09.07.01.01.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:35 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 14/16] include: pe.h: remove message[] from mz header definition Date: Fri, 7 Sep 2018 17:00:38 +0900 Message-Id: <20180907080040.4967-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010246_860911_32309510 X-CRM114-Status: GOOD ( 14.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP message[] field won't be part of the definition of mz header. This change is crucial for enabling kexec_file_load on arm64 because arm64's "Image" binary, as in PE format, doesn't have any data for it and accordingly the following check in pefile_parse_binary() will fail: chkaddr(cursor, mz->peaddr, sizeof(*pe)); Signed-off-by: AKASHI Takahiro Reviewed-by: Ard Biesheuvel Cc: David Howells Cc: Vivek Goyal Cc: Herbert Xu Cc: David S. Miller --- include/linux/pe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/pe.h b/include/linux/pe.h index 143ce75be5f0..3482b18a48b5 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -166,7 +166,7 @@ struct mz_hdr { uint16_t oem_info; /* oem specific */ uint16_t reserved1[10]; /* reserved */ uint32_t peaddr; /* address of pe header */ - char message[64]; /* message to print */ + char message[]; /* message to print */ }; struct mz_reloc { From patchwork Fri Sep 7 08:00:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10591877 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 2B26169B3 for ; Fri, 7 Sep 2018 08:17:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18E9128825 for ; Fri, 7 Sep 2018 08:17:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A2932A651; Fri, 7 Sep 2018 08:17: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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CF63228825 for ; Fri, 7 Sep 2018 08:17:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VU65njjwGwOm/qxSjvqvGQiNp5JDSi1XwmJKUYfmHco=; b=M8MAtpVq/VsTSi3VqMRuHvt4In 1458cBJ5izhuwKIp4b9VopfAOe5nSJeF/OC/+DzmrCKiUPwVDd3V/W9/iNRsmNx4E20YPf5erwxtR slSSQnXOe3GwuVAoc9Q1vFGMPiMfQ5/gJMM/1ysK1AjJSAXzdxHVVAVvh4rGbXlJyDoi7RiVt9avW iXtr6tzFO35wpX/1b1IOmovM1Teau4qNs1/CgJoEh6sST7nke+jx3mlPhBOKOCjh+e7ex4PKqyJSb MfEM7BaL7KMN6Sst49JUFB0y+zAqP9qcIHVh3XZl2h6hdT0YNZ5zvGXivqISD6XeUzorXbB97eD9n CSyt2G2g==; 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 1fyBxA-0004Q0-1L; Fri, 07 Sep 2018 08:17:20 +0000 Received: from mail-pf1-f193.google.com ([209.85.210.193]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBjD-0003JF-C1 for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:02:58 +0000 Received: by mail-pf1-f193.google.com with SMTP id s13-v6so6630326pfi.7 for ; Fri, 07 Sep 2018 01:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X+GJm3Xbex0yl0OP8EjZbRJpEMSGQ2q0tg8RxWU9Kqk=; b=TIULu/RGQB3wXUBgnC5RwUQ9/bNFnHHSDDKNtaFC+Q8/PpJxLVYEw28tUbns0p3F1L u1PsnlOT3uNO/5a7ZeZEKpa8FEhI8W/IQeNDmXKvPECPhg9oFZRuRJs9LJsfYkxL82ic 4AeW/x0IC9qVSA2Z9h3APE+d+YfNkSakbAPok= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X+GJm3Xbex0yl0OP8EjZbRJpEMSGQ2q0tg8RxWU9Kqk=; b=LTuQsZuzKu8H3agGfhZ+brsz7ZZKLEFZy+XQwWjoPpExuMhekn84ThH5hZqnLmOm3B +XQ8DVahTl+Jt8zauos8mMAAXOCMQGIKzkU9kpzOZLYBAYWgGFJFvBpecEMwPt+5zecH Dvn20xYQcuCQTTRKfvkgRB3VQLRJq4L5gQAC5Ak45mckjpdA+xMCDVwaW2G5Ez+iCSq0 agzBP3IWZySnLGUPX4OzaQUAh9fNqBO2nRzBImEzjfVK3VYciVNZpSdPaMDtH7zme068 cy6ZFQSP2EIeilnSZ6QwH1HCWsiwAU8KO0IRAvmaEU5boqEzW2LuK89nueVZGaYr2Jz6 JaWg== X-Gm-Message-State: APzg51BwnqEoz42pE77+i4hgKhv9ibW+GYtQjPXYf7d2+wwxbFxxzrcm 1nTVjIcveBjAbZaq9MufTl0jxg== X-Google-Smtp-Source: ANB0VdbOc4iutIfuB35UT4h5/yppqEf1QWXd1j6fTnPU7S/KBzHDzVGpnHnMUMHQXAL8WleQ7U5nyQ== X-Received: by 2002:a63:4826:: with SMTP id v38-v6mr6907762pga.379.1536307304938; Fri, 07 Sep 2018 01:01:44 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r19-v6sm10530577pgo.43.2018.09.07.01.01.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:44 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 15/16] arm64: kexec_file: add kernel signature verification support Date: Fri, 7 Sep 2018 17:00:39 +0900 Message-Id: <20180907080040.4967-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010255_453248_50E81BEF X-CRM114-Status: GOOD ( 15.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP With this patch, kernel verification can be done without IMA security subsystem enabled. Turn on CONFIG_KEXEC_VERIFY_SIG instead. On x86, a signature is embedded into a PE file (Microsoft's format) header of binary. Since arm64's "Image" can also be seen as a PE file as far as CONFIG_EFI is enabled, we adopt this format for kernel signing. You can create a signed kernel image with: $ sbsign --key ${KEY} --cert ${CERT} Image Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/kernel/kexec_image.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 5eb18d0cb513..e7de9500bf0b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -852,6 +852,30 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config KEXEC_VERIFY_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE + help + Select this option to verify a signature with loaded kernel + image. If configured, any attempt of loading a image without + valid signature will fail. + + In addition to that option, you need to enable signature + verification for the corresponding kernel image type being + loaded in order for this to work. + +config KEXEC_IMAGE_VERIFY_SIG + bool "Enable Image signature verification support" + default y + depends on KEXEC_VERIFY_SIG + depends on EFI && SIGNED_PE_FILE_VERIFICATION + help + Enable Image signature verification support. + +comment "Support for PE file signature verification disabled" + depends on KEXEC_VERIFY_SIG + depends on !EFI || !SIGNED_PE_FILE_VERIFICATION + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index d64f5e9f9d22..578d358632d0 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,9 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&h->mz_magic, "MZ", 2) ? "no" : "yes"); + return 0; } @@ -102,7 +106,18 @@ static void *image_load(struct kimage *image, return ERR_PTR(ret); } +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG +static int image_verify_sig(const char *kernel, unsigned long kernel_len) +{ + return verify_pefile_signature(kernel, kernel_len, NULL, + VERIFYING_KEXEC_PE_SIGNATURE); +} +#endif + const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif }; From patchwork Fri Sep 7 08:00: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: 10591879 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 9FB495A4 for ; Fri, 7 Sep 2018 08:18:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C3222AC91 for ; Fri, 7 Sep 2018 08:18:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C1732ACAC; Fri, 7 Sep 2018 08:18:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E36EF2AC91 for ; Fri, 7 Sep 2018 08:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GSxWYboBim20iHZWeAsqTnt+M5CEaGDqPpAlb+zUCck=; b=asTzKG6PKpC5HXf1zN/ON8jduh 38gET3i3cO6pLTyRJOISY7Ib7NmKCHU4uHyWGU+FVDACdQWR+xgJoPL2McaOCEcPbUoeCYhQCwMHs zZM5mysjfsBJYbtDwKAsHLaBWMpJYul+LIR0B3IdfujrPRKtiR6xD3qoVcjFvo8idAYTPuc+32lXA 1k9IqVFm3X1kvE483ndvT2CCO+8sczJ9VYw3IxDLSTXvcY1L9z3L3GFB8vY0K9aIdnhnkFpnsQdAo d4vOeQoxyOzWiof9Jm3Oqjev8LW5Po/8C29cLp3KIAvzJPnvXGUJxlqnPYoEJ1u5eTunAMat2MDUn G3Uwhr9w==; 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 1fyBxs-0004jU-FY; Fri, 07 Sep 2018 08:18:04 +0000 Received: from mail-pl1-f193.google.com ([209.85.214.193]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyBjO-0003M0-3y for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 08:03:07 +0000 Received: by mail-pl1-f193.google.com with SMTP id j8-v6so6224640pll.12 for ; Fri, 07 Sep 2018 01:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=PUuXrmrhzXKdXLed1SIuT8fjgiUdG2uDYfqr82pc5ulwV00S7s0y1ONHe+4D9P0HS3 Xa74+tT+vF3yEETwBlMtSnKWua/f6afVjTDULUfRHaQMYEoegvwXamIHA+dGYRpr9fXw lp/17gfVbPnFF3OVqd0Ziwek3IQizPPI7r8NE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=VZpMiSP2fd2cjn/2YSl1yta7CiqygY7fHaJbNPKcjAT48PoySGqz5g5LW2uehfhYIq 0blf9p0UBzFzXGVUhaxyBZpkNolQ3YmHpOSIeGrPuPlPFZZNyhqVMmBLh7KRmA4zTV++ wtVykm8lFGtO8vE6puAUAUmoEh71Tsn+C8xpdvsJ5ZcqZhqCMgN8CJyVOt+5tIUEUY+d 0oef2XauHA2oWHYCI8HpPymJmLDsxrzoAKsVVWTSOBCqgvn1ajj6oBweUve7YLuHnRPV z4KP2ROker2EF/xscoxFJx/TY93Vv9u687mHENwlqvSlmtnLUvIYv8wqeAgEjdOdxwVe 2rpA== X-Gm-Message-State: APzg51DQS/Kf+26r8qTYOTj46dGxw3dWoDWNqWrp6/5qqc4E9BbE6ZU2 PtnaAg4F32oA6vpySbNTiHJAeg== X-Google-Smtp-Source: ANB0VdaAw4JGA5PGH3LsHjF7IpXsyUJhuSDjAZIZWuFsc1UDQYp/duZAnmUOwq2146Neg1ZDJaaAVw== X-Received: by 2002:a17:902:6b47:: with SMTP id g7-v6mr6800958plt.128.1536307314969; Fri, 07 Sep 2018 01:01:54 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 22-v6sm11078582pfl.126.2018.09.07.01.01.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:54 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v14 16/16] arm64: kexec_file: add kaslr support Date: Fri, 7 Sep 2018 17:00:40 +0900 Message-Id: <20180907080040.4967-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_010306_200540_17A9A015 X-CRM114-Status: GOOD ( 17.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Adding "kaslr-seed" to dtb enables triggering kaslr, or kernel virtual address randomization, at secondary kernel boot. We always do this as it will have no harm on kaslr-incapable kernel. We don't have any "switch" to turn off this feature directly, but still can suppress it by passing "nokaslr" as a kernel boot argument. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/machine_kexec_file.c | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index ecaecb122cad..967db9824e3f 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" +#define FDT_PSTR_KASLR_SEED "kaslr-seed" const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_image_ops, @@ -45,6 +47,32 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) return kexec_image_post_load_cleanup_default(image); } +/* crng needs to have been initialized for providing kaslr-seed */ +static int random_ready; + +static void random_ready_notified(struct random_ready_callback *unused) +{ + random_ready = 1; +} + +static struct random_ready_callback random_ready_cb = { + .func = random_ready_notified, +}; + +static __init int init_random_ready_cb(void) +{ + int ret; + + ret = add_random_ready_callback(&random_ready_cb); + if (ret == -EALREADY) + random_ready = 1; + else if (ret) + pr_warn("failed to add a callback for random_ready\n"); + + return 0; +} +late_initcall(init_random_ready_cb) + static int setup_dtb(struct kimage *image, unsigned long initrd_load_addr, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len, @@ -53,6 +81,7 @@ static int setup_dtb(struct kimage *image, void *buf = NULL; size_t buf_size, range_size; int nodeoffset; + u64 value; int ret; /* check ranges against root's #address-cells and #size-cells */ @@ -85,6 +114,8 @@ static int setup_dtb(struct kimage *image, /* can be redundant, but trimmed at the end */ buf_size += fdt_prop_len(FDT_PSTR_BOOTARGS, cmdline_len); + buf_size += fdt_prop_len(FDT_PSTR_KASLR_SEED, sizeof(u64)); + buf = vmalloc(buf_size); if (!buf) { ret = -ENOMEM; @@ -164,6 +195,20 @@ static int setup_dtb(struct kimage *image, } } + /* add kaslr-seed */ + fdt_delprop(buf, nodeoffset, FDT_PSTR_KASLR_SEED); + if (random_ready) { + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_KASLR_SEED, + value); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + pr_notice("kaslr-seed won't be fed\n"); + } + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;