From patchwork Wed Apr 25 06:26:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134226 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp470696lji; Tue, 24 Apr 2018 23:27:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+S42Kd+WUyGATJO4SvW43UXRPc4YPSpu/2pv4yOK26BUfJNHBzdTazW/sGY6kEulqzFZhF X-Received: by 10.98.68.135 with SMTP id m7mr26626546pfi.57.1524637620905; Tue, 24 Apr 2018 23:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637620; cv=none; d=google.com; s=arc-20160816; b=oZKWv6+9oYNU1f5CphSHwKNCYz2xaS4r+dvW7Up7BFpPv8jRM3VAInb6Z5ZLhvbwCp f5aqDFoA4ILx8cHkzkPjuMXu7ANfHw+PciUElVQW9pAD7JefMEIiiYeAlRVwgfwX9dbY GGzgGXYNnGnWW3LyPDuqg5l8OJYLL/wpwEIJw4XEhRSaiZKfgUWmJK4QlRsZM6WdMaLx DAWH3JrkFZfVBADGn9IvM9vn92/I6Q0CiXraRm8Oi0I/RBuWC7MXTEjN03na+v1NvuiE F3NIMdF569QE2WoMVq1dC1tHQHrs0ofMtuaIHz0qgN3U/bdr0moDP3JT06RTSx+uzQLP cgFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=tzU/jdZ0/5w0haUgvxPouRVkRHqKTPwAph/VuQGQ4f8=; b=gFcN+GF/nxiLaordGMibj+QGUbQuoi4/56BHtYOEprGyESFA71ZtfSi5tXJmop7wV9 DISUkLW56yg9VZxgW5IndfXBtc0jVcJ86ggXZzlJpGfO2jexrNAHojMoy3c/ERyPYrik 7462iDTGnjyiEJNBBln/eU7r3NXat9NnvnOkPCySN9s3Qfeyi5p9Ghk21FX93qColNPc ov31lRYRoPTAQP+jqVQ/Fk+AceGEf5/Jvd+kJqf6N4/pyQqkGguulUGKFg5Vcf1lBfXx 72O5M7m+92RSnnF3V0DFa1UjCwwP8T+GUNyH+xF+lDVzzLo4aB8Gv/HjLkAF1XzZa171 5gPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MzoRD2ny; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6-v6si15972960plz.211.2018.04.24.23.27.00; Tue, 24 Apr 2018 23:27:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MzoRD2ny; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424AbeDYG06 (ORCPT + 29 others); Wed, 25 Apr 2018 02:26:58 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45977 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750929AbeDYG0w (ORCPT ); Wed, 25 Apr 2018 02:26:52 -0400 Received: by mail-pf0-f193.google.com with SMTP id l27so14307506pfk.12 for ; Tue, 24 Apr 2018 23:26:52 -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=tzU/jdZ0/5w0haUgvxPouRVkRHqKTPwAph/VuQGQ4f8=; b=MzoRD2ny2c4oB+J+5dd56RI8qHyZdI0rELparsEkSPWY3ClAdfdkthkGPqYyMzSNBd qNW96aS54Am4mR6TsDq55kEoSBe5TRqVDKt2bSo1BYyIy8J5vKqj1avO4uojOzypZuGz NL5NC7Wz3K1yAEycyLWZbpXsiNd7xRpNSDcNY= 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=tzU/jdZ0/5w0haUgvxPouRVkRHqKTPwAph/VuQGQ4f8=; b=nSKW7HnaZUxrsijZyrZCi4+0s/s9GC3jS+EddEtJtF66M/bgGqRMu6oZhKwLKN6VQ0 XRU2Rzvz1s7TjWVyroTtcWf+bmkQRtilBfTk2r24+vCR63oQBFz53Fkk5/SQ0Suex+rr Y/HIHZ3U5QqA62mOsp4fOTWDNElDVbdZi7B6sMqaKj1p6G9ecx8nvIyK8Robwg/A9Iql U7zHQr38yI4AUj+kE0RpEoHGeWRLC0iZeiau2cBAplWOplgWPAYwNKtnE8XFutVTb67v /cF3MoFq1mIpDwl6QUM7490kxnPEiVmPRU3c5sSmPoM5Uj8T7oGzibneMhuGccinMsWG uqtA== X-Gm-Message-State: ALQs6tC7Q6x5okZkQtloVn7+iuAaKkN1Ugwbyok9elO/8YKVBiz+hGQU YAI2MM7ufk5Aet2yda3LGgM/Sw== X-Received: by 10.99.184.10 with SMTP id p10mr16586542pge.250.1524637611971; Tue, 24 Apr 2018 23:26:51 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m65sm40336646pfg.135.2018.04.24.23.26.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:26: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 Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 01/11] asm-generic: add kexec_file_load system call to unistd.h Date: Wed, 25 Apr 2018 15:26:19 +0900 Message-Id: <20180425062629.29404-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.17.0 diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 8bcb186c6f67..745bad1d8269 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -732,9 +732,11 @@ __SYSCALL(__NR_pkey_alloc, sys_pkey_alloc) __SYSCALL(__NR_pkey_free, sys_pkey_free) #define __NR_statx 291 __SYSCALL(__NR_statx, sys_statx) +#define __NR_kexec_file_load 292 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 292 +#define __NR_syscalls 293 /* * 32 bit systems traditionally used different From patchwork Wed Apr 25 06:26:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134236 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp472771lji; Tue, 24 Apr 2018 23:29:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx499dDLZIQall5TvO32J+ahxVKnkhH1Ioh67tCMVP+Df8pLG1Q4AnCzSN7TQh7KUwaa2/omt X-Received: by 10.101.75.74 with SMTP id k10mr20948667pgt.227.1524637778945; Tue, 24 Apr 2018 23:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637778; cv=none; d=google.com; s=arc-20160816; b=pZBCFifGb0gY3hboXIzt1aeVNN7CT8gCNrIXZTyb9m8tOey4T6FN2AYihP0gQm7LRt TRWvm/W4OYn2pLS2kFITr4SzGaEgwTAMmjJfFng4ISW/ZLz8gRG7/58T4KxZgSZi34VS +1fwXOr6AAqQAXTTQ836yg/Fh0CbxuzrR2A3FeqKmqiuoEDTHO5/fF6C6C13yLbuyw2s 8G7toBuNXgnZ9oYCfHWSXH6I9Lgu1W3vW/J3NgNLSvoO1UWddpio4jfZKLyE6wqZro81 f0xxi/tqEYSUTpHDn0mkA748ggv0X8XH8edz9ZiG+5WYCWOYv0GODOTJte+Fi1sxR6vh ruyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=s3RbGgzhDsKg1yhv4ME5GjDWSW9jqtpalELaALG50C8=; b=GVHlm42CLs4bYqcL1ZfmsyDj0T/f9x5Cs5lRU0U746KhOC2GmWYDpRcVkSpUhp2C9W moQBOYgn84h1qCZRC2K3RbGnPgCkGofRHjf3Jmv8qcU+V7gofcGNsgBYLgNnMaG9uwVx gmwR68qb5m7lRy71MouMlW4o7m5Y9l13SGlL9vlWHxszWRWoOI7s9uuXfHv8/FJankD0 BgtycyvswU79qzNtjM91sDGVMXU3ge/oSJOIvitpF3E/wdOL6d2EATmohLoJBQGv5doW jNGvmrvzcBpO1UYn9Go/z0glRuAr0lbrcdgdUpnU+2JybkK4HjxXqB72AQ4KA+YRIkrH j7wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AbTMgnNy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s10si13381616pge.41.2018.04.24.23.29.38; Tue, 24 Apr 2018 23:29:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AbTMgnNy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751651AbeDYG3g (ORCPT + 29 others); Wed, 25 Apr 2018 02:29:36 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36905 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751320AbeDYG04 (ORCPT ); Wed, 25 Apr 2018 02:26:56 -0400 Received: by mail-pf0-f193.google.com with SMTP id p6so14307764pfn.4 for ; Tue, 24 Apr 2018 23:26:56 -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=s3RbGgzhDsKg1yhv4ME5GjDWSW9jqtpalELaALG50C8=; b=AbTMgnNyH7+y/nU/ztK4dGx1cJqczXFzGJhxlTMvnN9ehdJK2CJZaKEm4EOYLbqedP zeV7gKAC+10JXFna2HIgx/OuFUOlQ/k66UXT2u3wDfPt0/cchDeuis1Lxg/PhaU78JfL dtNKm8B4Vbzg9BAt4Gv5LMM9yeiPsGtGGVca8= 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=s3RbGgzhDsKg1yhv4ME5GjDWSW9jqtpalELaALG50C8=; b=rpB780aPLaYefCsZc+LgMF/T2bw1JqTCSTzRBRJwrNg/uOZXGnemKtbbN8jrnlmr/p aFzniE7JPW8SZ3LHcazywMEu2J/SMGegHGdbOZRC0TaGneOyN9kYNJuZB9C5QcsP/zyl mPlxRyrDqBZkrTfKW0ECxWHY2pDYphRFFDijYB9AoRSQJxDi1o2Hxs7sl7dkdN4e7phN GD3ttdib7wJB2KS2DCTOQ2pY4grHF3AKYJQj/myste7t0ki1Y5luc9m6NBSzJa+EtSeI hBZzQJZUINDLaGm3iR1nbEMpbel+LLs2rP418PbXrFud21txJBBYkwRt2w1f82B9q2A3 CC2w== X-Gm-Message-State: ALQs6tDwWARTE/9A2n3yZW0Z+gCPeZHwqd4qvd8vdAZ/FQN+wqWNXsqy 7C8LNh5Txca3fKaGC2dBS9KzcQ== X-Received: by 2002:a17:902:82ca:: with SMTP id u10-v6mr5170278plz.160.1524637616423; Tue, 24 Apr 2018 23:26:56 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t1sm28193765pgs.47.2018.04.24.23.26.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:26:55 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 02/11] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Wed, 25 Apr 2018 15:26:20 +0900 Message-Id: <20180425062629.29404-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: 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(-) -- 2.17.0 Acked-by: Dave Young 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 75d8e7cf040e..eef89d9b1f03 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -78,7 +78,7 @@ void * __weak arch_kexec_kernel_image_load(struct kimage *image) return kexec_image_load_default(image); } -static int kexec_image_post_load_cleanup_default(struct kimage *image) +int kexec_image_post_load_cleanup_default(struct kimage *image) { if (!image->fops || !image->fops->cleanup) return 0; From patchwork Wed Apr 25 06:26:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134227 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp470927lji; Tue, 24 Apr 2018 23:27:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx49k9E5bKlCzaBsQIRKc3ZIvfKE2tpjtIOLu/V4qS3sp88X5u6e4pQJRd220vqXuQXigFWwA X-Received: by 10.98.178.4 with SMTP id x4mr25910399pfe.21.1524637637563; Tue, 24 Apr 2018 23:27:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637637; cv=none; d=google.com; s=arc-20160816; b=rFzAPSfFRLSpuATdJupAMYBVrJQ7lLLcOaoekqy2dDjoIZalI+wUViIu6/iLiiqGRU ah+5pNqNm6fXql8oMIkhB2UdNJrOG35p3wsAV/RnVEJsM+tSIn2ftyHaXAc4nG6q2tOp XK+A1EsWVIfro3L78S/Mm4iDTgI8h72PRCCMEGM+q9bCZ6EzCf9WFw6Fe/NsGlcEf9/v XCLmtAGO3vSZ8Ot/z9kjgSaRALqU4L2DRKR96+3npfdsPm16fCYX7lehXk42Kwir6KjZ SNN62y520mrRLmDI2Cysf0RQEOUINFnv6n6FHilB79H2Yl5G98T+en/Cjay6qG1t3/CZ JnHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ForuHUf7fRKkbyO6U4zbwFSqEvXWjf/5Ol9d4UtEg9Y=; b=nBr3c0WToy1o1pcmmIZpmWMK/zviEwiFbtULQkAJqSjY+rCee+dN3a3KGwviS/2/bb MvNvV2/NDs0rQCwenPZheQlt9jrt9/0Kik7Rb1p7fDr86Au16I47hc9BWuhE2H6oxyBp D2xDoIVdIlNnwNw4YXFWvdzEf6Ms0Om0ZloSID+TdOJHCdwYWVPgr+NQ8W+guwBiL47E 6Bpy2DSuuIjFOLUh220P0zL7b2Tfc8A96p85KacfRf4CMxggBCgMQyZt6MCAbjKeXCC4 JkhPOcjWBznhZDv+xAvMISnUG2/BPuAEZg4no7kwAS9N42fzGRhraMq/bx3BLVEBH0VG d8MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ITQBf6iS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o24si8177612pgn.36.2018.04.24.23.27.17; Tue, 24 Apr 2018 23:27:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ITQBf6iS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751494AbeDYG1M (ORCPT + 29 others); Wed, 25 Apr 2018 02:27:12 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:42999 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750995AbeDYG1B (ORCPT ); Wed, 25 Apr 2018 02:27:01 -0400 Received: by mail-pf0-f195.google.com with SMTP id o16so14304833pfk.9 for ; Tue, 24 Apr 2018 23:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ForuHUf7fRKkbyO6U4zbwFSqEvXWjf/5Ol9d4UtEg9Y=; b=ITQBf6iSIlao16ECv8VirqBUtgAhKKF0jq9Hm5Ivm3mF5Oltyz5jikcUvHNghOtRy6 FZyPlO7Op8VlIaN2h0L4Ux92JViCHh5NitnhOxU8YNobhWYxsZMtZinK4xJxZbnM7QBB rFXd+qkOWRx9zqsIoRpCFLIIJpmww8ykdLyQw= 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=ForuHUf7fRKkbyO6U4zbwFSqEvXWjf/5Ol9d4UtEg9Y=; b=sOpR5x3N4UX7O46soTDtU3F/Q++P+QM117cFId7n57OfCKPVYetsVoQ+/eU0DvowNM yNmxnBRrRHEOk/Y8LPxVEdOFAlUuBbileSmRit0s1YjRpteEA6p3c3Vh8B7YbmzjJYG8 l07tHdTyRv7ewT5cHiBd1QxzP62rzLqIScYUO6tFHqzbSHtuEPBF0hHgkS1VW51auUVO GDhcDzrNKvIzLCNOgUtD8qj6tvuxYupD7+oP72q095huUDlthk2GIvobkSuiAb8HS829 7zYpVpoafkl5EcA9MrVaNFpl/2rYw50DiYQUJJ2chz9qc3VTdBs42sRmQHgLeJNAgAR5 uuog== X-Gm-Message-State: ALQs6tAeP5CgdUS6wPRLHqWYBXNuLoVRY3Riao54YvywLcGgxm++4y1r heR2+xhQIkGGPNSe794xL4BB3Q== X-Received: by 2002:a17:902:b191:: with SMTP id s17-v6mr27711983plr.339.1524637621153; Tue, 24 Apr 2018 23:27:01 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b3sm30407840pff.11.2018.04.24.23.27.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27:00 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 03/11] arm64: kexec_file: invoke the kernel without purgatory Date: Wed, 25 Apr 2018 15:26:21 +0900 Message-Id: <20180425062629.29404-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On arm64, purugatory would do almosty nothing. So just invoke secondary kernel directy 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 Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/cpu-reset.S | 6 +++--- arch/arm64/kernel/machine_kexec.c | 11 +++++++++-- arch/arm64/kernel/relocate_kernel.S | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) -- 2.17.0 Reviewed-by: James Morse diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 8021b46c9743..391df91328ac 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -24,9 +24,9 @@ * * @el2_switch: Flag to indicate a swich 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.(physcal kernel entry) + * arg2: Third argument passed to @entry. (physical dtb address) * * Put the CPU into the same state as it would be if it had been reset, and * branch to what would be the reset vector. It must be executed with the diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index f76ea92dff91..f7dbba00be10 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -205,10 +205,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 case of kexec_file_load syscall, we directly start the kernel, + * skipping purgatory. */ - cpu_soft_restart(kimage != kexec_crash_image, - reboot_code_buffer_phys, kimage->head, kimage->start, 0); + reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->purgatory_info.purgatory_buf ? + 0 : kimage->arch.dtb_mem); +#else + 0); +#endif BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index f407e422a720..95fd94209aae 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,6 +32,7 @@ ENTRY(arm64_relocate_new_kernel) /* Setup the list loop variables. */ + mov x18, x2 /* x18 = dtb address */ mov x17, x1 /* x17 = kimage_start */ mov x16, x0 /* x16 = kimage_head */ raw_dcache_line_size x15, x0 /* x15 = dcache line size */ @@ -107,7 +108,7 @@ ENTRY(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, xzr + mov x0, x18 mov x1, xzr mov x2, xzr mov x3, xzr From patchwork Wed Apr 25 06:26:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134235 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp472244lji; Tue, 24 Apr 2018 23:28:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/IY+2Wea3aRObzrEM47PL0DaQ1lw0fHkckVL2t+wtH8tOyQ8qdP22OdBCNc3ItJempYu1R X-Received: by 10.101.66.139 with SMTP id j11mr22577047pgp.370.1524637737102; Tue, 24 Apr 2018 23:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637737; cv=none; d=google.com; s=arc-20160816; b=xoBaICqi9//kO47XzRieRR0wETUvdXB+T2h9QIqBukQ3AzPBgRKcx9ss5tzY6oSFtG +J0JuH3I5DfPiIvF5yOfa0tyllCpSJwWs8djp4rKvd/UhuR52gNiAcpjL5cwzEGPbk/C RVL7OouNg8jtZyE7It/pfaIDanXsSvWLCORRLsOF9Ti1dE5KU5PgeAzqsuiSi3O0C0qm C0Qbf0O+hwym8/cHeg9xDwZ4B3M7Mn45J79CUMgsL4itVzJ6Cx6ENTfkFCoCroJtN2Cc wpBWw4UBsbs8RRTKh22hYaE6iTq6/zAmXKD3D/8+rra8kkQrx9BhPHlCtalT/nuKE2Da v5vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BGy/B2xlXyJiO0NTOmJQQedzIhM7vraX1PekUsLXCUk=; b=yvqgUWmaOt5j35GsEHvyun0X7Nw4xAxvDzjzOy7XJgNm+xSuW1sW9U9Kr2TSLjEjfg MjyYwxn/6wbdNIY1vW5tL7LucLaPIcvV542VYfyn8vNIefA9ARcfYEThy9t3TpuQCfYo KZJAopEoaeMrbmDX6e3qJPF4qsZMdg/wyK7hN9SjGRSoIQhdUFai2oQBU7/O2vDszIg/ iUMwlwCmsgF3W/3/J05Q14EjNS0uIHKrmpZSIUJ68j6r+ME6/aYOCivF1akYRCc3o9X3 XAmVFtxsmKwxJ47ZXqFFpUIGd53qteKv2tiRAafOMz6zKA1rpV9UYxTKVrvlrCq6wGz5 yaTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OimhlRjX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si15899498pff.24.2018.04.24.23.28.56; Tue, 24 Apr 2018 23:28:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OimhlRjX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751936AbeDYG2y (ORCPT + 29 others); Wed, 25 Apr 2018 02:28:54 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35826 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750929AbeDYG1I (ORCPT ); Wed, 25 Apr 2018 02:27:08 -0400 Received: by mail-pg0-f66.google.com with SMTP id j11so12600882pgf.2 for ; Tue, 24 Apr 2018 23:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BGy/B2xlXyJiO0NTOmJQQedzIhM7vraX1PekUsLXCUk=; b=OimhlRjXJaVorW8wcmYBqSqFfwpgYs9cubMILUJkitObDkCi2NXpNZOtnjfbsl47Uc 8Q5EoUrZ44L8RcluE8prTfKaD6qtBkaJUVgd4+RpKnYumkknU83Y/Ik8eT3dAcnJ96cU 5SalaoZ6evwxdCr8igU7hyvyJ6fBXAWv/MQNw= 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=BGy/B2xlXyJiO0NTOmJQQedzIhM7vraX1PekUsLXCUk=; b=BGkEPpqcmNUykvc14RgCx9O3hTm8yknHZ8SAGYcw+CoAPrf4styBfSMNXVzfj7psvQ +cmbbO1xMHxOZfc+5gxMV5iEXzMSyAD2c+a+he3hhRaAnRO+f3iGwErAF5c381z5Fioq 9lvPH6u5GJNqGMKqkmrwstG71mSwsDJUKAbZCMDmJ9uBrE1HWBioOAtsYMp4VmuKrkng ZXJXBEu5iYLxo0iuQ1kAOZKHhplYiqnC1R5wrFTzmMYaqXGoJ2N9swnPGZoJkOdsuT+W bJQxAQe1u3IpZhG6KYofm6q2uNBUIQ250SpWccViJkE0aPNpWZcOAn/EbjScj1IyC/L8 CGmg== X-Gm-Message-State: ALQs6tAe6xWMK3tmBfUhG5o0PM4rWrZTvEXeu3vxHp9OIH6VpI73E440 YKHCsLNqqPmkQ9fHumNWv6DJdA== X-Received: by 10.98.237.17 with SMTP id u17mr26719524pfh.78.1524637627702; Tue, 24 Apr 2018 23:27:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z16sm27906062pfn.101.2018.04.24.23.27.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27:07 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 04/11] arm64: kexec_file: allocate memory walking through memblock list Date: Wed, 25 Apr 2018 15:26:22 +0900 Message-Id: <20180425062629.29404-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We need to prevent firmware-reserved memory regions, particularly EFI memory map as well as ACPI tables, from being corrupted by loading kernel/initrd (or other kexec buffers). We also want to support memory allocation in top-down manner in addition to default bottom-up. So let's have arm64 specific arch_kexec_walk_mem() which will search for available memory ranges in usable memblock list, i.e. !NOMAP & !reserved, instead of system resource tree. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/machine_kexec_file.c | 57 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/machine_kexec_file.c -- 2.17.0 Reviewed-by: James Morse diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index bf825f38d206..2f2b2757ae7a 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -48,8 +48,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..f9ebf54ca247 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * 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 + +int arch_kexec_walk_mem(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + phys_addr_t start, end; + struct resource res; + u64 i; + int ret = 0; + + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + + if (kbuf->top_down) + for_each_mem_range_rev(i, &memblock.memory, &memblock.reserved, + NUMA_NO_NODE, MEMBLOCK_NONE, + &start, &end, NULL) { + if (!memblock_is_map_memory(start)) + continue; + + res.start = start; + res.end = end; + ret = func(&res, kbuf); + if (ret) + break; + } + else + for_each_mem_range(i, &memblock.memory, &memblock.reserved, + NUMA_NO_NODE, MEMBLOCK_NONE, + &start, &end, NULL) { + if (!memblock_is_map_memory(start)) + continue; + + res.start = start; + res.end = end; + ret = func(&res, kbuf); + if (ret) + break; + } + + return ret; +} From patchwork Wed Apr 25 06:26:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134228 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp470978lji; Tue, 24 Apr 2018 23:27:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/nksrVFK7fEQj+1vYvlypzSE/4k+PqlpYwEUH3kZuDxI71mA8ocB60JHPuqP5S/3mQB8rq X-Received: by 10.98.242.13 with SMTP id m13mr7391913pfh.170.1524637640681; Tue, 24 Apr 2018 23:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637640; cv=none; d=google.com; s=arc-20160816; b=SdS7J6KHJ4zz0EgtV1uHMIvgbtGQX6vXd3EE2izeg91UAPaj8tTTao0+vDwyUhKGrj 0cQX65z6OPXTSTUFFZT7dRw9GCzZ9B7+xsyKCILohPPUS6K3k6kiOOfTLh3bZ3cTCdmV miJbVJ017Sm8/t8Hxvr7dDiFMhTC5+/LZOrGvJPD2vhaSMj6h2Bi2QfF0vDD7DJ2PbTJ zHL9mEB8toEo8uFZesrSl/f+P2c3Wu5YuekZnQOtsb8I9baos5LB+CYf54HogT3XwP64 glcHfWMob4h17bzcGpAgv5eTWQJ/y4JCJUgB3xK/djLjE92UfUjgzR+uNz9rff+smk1M Qq6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=GxstDnPpKBuoMMwAmoI85QXMWYDKZl9Yr0/WjfQZahU=; b=SdPPqywqHc2DD6b1yPYlobvh//ywmaRv005gHosXKq/RCvW7CbdrH40lBg39bbunoc 7NDf6JgCZqKrs2fkOJisjRbimPF99nqhX33LnUz+BAqYOczCmJIHKzneFQikFFRzi+vg 3oytk/dPWQwQ8kSW8Kcx6xaXySnDuyuW6hSbzWNY4HnSOw+rsemIdXufado/z7VCGF4r RE4Tzrz9jrZkWpYVFsbc2u9QiPADcaS+cuwDFVDPHFao5MD5iav0WsLX3FXvTtQlligQ F4T7aB2snG1959QeToIABdLL3KhnP6lHXVEPZz8xa9ZMj+l0sPgWMZARmpkb9mx+1bnG zcWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O9esqQdG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o24si8177612pgn.36.2018.04.24.23.27.20; Tue, 24 Apr 2018 23:27:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O9esqQdG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751512AbeDYG1S (ORCPT + 29 others); Wed, 25 Apr 2018 02:27:18 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:39379 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbeDYG1M (ORCPT ); Wed, 25 Apr 2018 02:27:12 -0400 Received: by mail-pf0-f196.google.com with SMTP id z9so14319745pfe.6 for ; Tue, 24 Apr 2018 23:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GxstDnPpKBuoMMwAmoI85QXMWYDKZl9Yr0/WjfQZahU=; b=O9esqQdGUnlJZQLJPdJ3MqlFA02ztagtJc9NRoWcy2QjntdzemtUlw+7ZVXu7SAch8 oyRH9akUq5/OimLJWU6O7oeKvbRFvJOfP+hUT0KuNUse8IUKMUpHozUqMu9hb8JhMGuC ZPbAyz/ptejvOMg4tNDjHld4mEygsuxGLTHDE= 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=GxstDnPpKBuoMMwAmoI85QXMWYDKZl9Yr0/WjfQZahU=; b=VsdkKDtOOCUpw4+eNU/h9ymYt7RzBwUw7RmvFwLK3m3agrvCn8o3irODJSPhQwma+d YRAyezFzM76M0Y/xwLUQOiWFrWUhepRVe5wI1bDGw/L9aLgMLcjts7Ed2aMgZui5DLSt zZu3sTdnl+aDPP0+qXy5Sl6fLvGf26mf4A2LqKqEAhJel31XyF+N4qo4tc8mcQl0QvQu fFhS+/dYm2411N8qydAlzj71tl8rtn4cAJF4bFli2nHhSGKABIY5mlx7s1th7DmHbYJa A4Lc0vwNXQZD0GbhwoVMXaRFzVLkS6AJj3pnrfRlVuZ4zePCJK++0NAyMifvujf3zhdu pK6w== X-Gm-Message-State: ALQs6tAtE5fDlMtLZWRO74i7F0htzEe31e+ZUYfyglSqRWte0dQI6LBG T4TdE0jnlQ5P++XFDEXCSUZ2J3462nA= X-Received: by 2002:a17:902:684c:: with SMTP id f12-v6mr28188233pln.139.1524637631851; Tue, 24 Apr 2018 23:27:11 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j125sm38606832pfg.188.2018.04.24.23.27.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27:11 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 05/11] arm64: kexec_file: load initrd and device-tree Date: Wed, 25 Apr 2018 15:26:23 +0900 Message-Id: <20180425062629.29404-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 a 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 --- arch/arm64/include/asm/kexec.h | 16 +++ arch/arm64/kernel/machine_kexec_file.c | 160 +++++++++++++++++++++++++ 2 files changed, 176 insertions(+) -- 2.17.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..e4de1223715f 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,22 @@ 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 { + int kern_segment; + phys_addr_t dtb_mem; + void *dtb_buf; +}; + +struct kimage; + +extern int load_other_segments(struct kimage *image, + 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 f9ebf54ca247..b3b9b1725d8a 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -13,7 +13,26 @@ #include #include #include +#include #include +#include +#include +#include + +static int __dt_root_addr_cells; +static int __dt_root_size_cells; + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb_buf); + image->arch.dtb_buf = NULL; + + return kexec_image_post_load_cleanup_default(image); +} int arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(struct resource *, void *)) @@ -55,3 +74,144 @@ int arch_kexec_walk_mem(struct kexec_buf *kbuf, return ret; } + +static int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + char **dtb_buf, size_t *dtb_buf_len) +{ + char *buf = NULL; + size_t buf_size; + int nodeoffset; + u64 value; + int range_len; + int ret; + + /* duplicate dt blob */ + buf_size = fdt_totalsize(initial_boot_params); + range_len = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + + if (initrd_load_addr) + buf_size += fdt_prop_len("linux,initrd-start", sizeof(u64)) + + fdt_prop_len("linux,initrd-end", sizeof(u64)); + + if (cmdline) + buf_size += fdt_prop_len("bootargs", cmdline_len + 1); + + buf = vmalloc(buf_size); + if (!buf) { + ret = -ENOMEM; + goto out_err; + } + + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) + goto out_err; + + nodeoffset = fdt_path_offset(buf, "/chosen"); + if (nodeoffset < 0) + goto out_err; + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop(buf, nodeoffset, "bootargs", + cmdline, cmdline_len + 1); + if (ret) + goto out_err; + } + + /* add initrd-* */ + if (initrd_load_addr) { + value = cpu_to_fdt64(initrd_load_addr); + ret = fdt_setprop(buf, nodeoffset, "linux,initrd-start", + &value, sizeof(value)); + if (ret) + goto out_err; + + value = cpu_to_fdt64(initrd_load_addr + initrd_len); + ret = fdt_setprop(buf, nodeoffset, "linux,initrd-end", + &value, sizeof(value)); + if (ret) + 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, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct kexec_segment *kern_seg; + struct kexec_buf kbuf; + unsigned long initrd_load_addr = 0; + char *dtb = NULL; + unsigned long dtb_len = 0; + int ret = 0; + + kern_seg = &image->segment[image->arch.kern_segment]; + kbuf.image = image; + /* not allocate anything below the kernel */ + kbuf.buf_min = kern_seg->mem + kern_seg->memsz; + + /* load initrd */ + if (initrd) { + kbuf.buffer = initrd; + kbuf.bufsz = initrd_len; + kbuf.memsz = initrd_len; + kbuf.buf_align = 0; + /* within 1GB-aligned window of up to 32GB in size */ + kbuf.buf_max = round_down(kern_seg->mem, 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.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_mem = kbuf.mem; + image->arch.dtb_buf = dtb; + + 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); + image->arch.dtb_buf = NULL; + return ret; +} From patchwork Wed Apr 25 06:26:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134234 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp472000lji; Tue, 24 Apr 2018 23:28:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/F6xPGZfRw9E0ZzVjGr7IqKERdawW1w0d4NRIuj1ytyJDlvAqPGNVvdD8+lMUpnTTOYyMB X-Received: by 2002:a17:902:3181:: with SMTP id x1-v6mr28125568plb.198.1524637714462; Tue, 24 Apr 2018 23:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637714; cv=none; d=google.com; s=arc-20160816; b=AHtzLL+QiOv8QOcSB58bTZ3LBMCrk6pg36C4sLK2Rwk9zIO9QLcPSOynGqsefEQd1t 4NMF2uxjmYuTDQdC/owvCtJ+wcpp8e7xTQFmycgaI9Vr1rSImEcaTLVkMkW/8/goh2sy ztHOKGGcvGO4HhVozSTllqjeExBR/UG8MCIi1bAoIl3JJydnPVcky7W2l8qU0Gfusz4k uVR7Q92t3Vv52WeyO+rwCn5CMpp+8ZL4CR5ow6QcK65gESAOSZW0e2RA+Okew0ksxoy1 qy4pibHJhRv5ztIQLZLtBCC8XOvNSATJK8bvDmoAbkx2dty8BPfPvLJLV/ucB54vXeF4 3rZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Hk17H4nlIgaxnc/FjRGL0OgFtKXzMGdb7qKjidLoWTw=; b=vUMDdDVx1jWIoH0who0MeDw70YeM1B4YBXVCEMBhnP4wvALdZkZ16ayZVJC7t/KdiL vb3DJ4Bih40JD6760je+csnA9irZVprEQziKAdJgArfi/RtZD4PO9nd89X2GVQFpQ9Rn m9trBeJSOEday0bU0qA9Kp0ucwLatMllR4+p3e+9uuuqNTzk4l5leEZmRi9VHzvajUDT IQ2CDXCHBoLO9uHsv11kFTd2O6ylsZsMoYWSkOid3VUiztTpT2cw9JcSkzMFk5ILOhYS xo0RlJqG4kVhK7cuIcUvVGdT+6x28yiswDUq89gsNpWtJahp4TZd9Up/4JRgJHq6pnAm eWsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SGUpMOso; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si15899498pff.24.2018.04.24.23.28.34; Tue, 24 Apr 2018 23:28:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SGUpMOso; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751910AbeDYG2b (ORCPT + 29 others); Wed, 25 Apr 2018 02:28:31 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36262 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751497AbeDYG1Q (ORCPT ); Wed, 25 Apr 2018 02:27:16 -0400 Received: by mail-pg0-f67.google.com with SMTP id i6so12608655pgv.3 for ; Tue, 24 Apr 2018 23:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Hk17H4nlIgaxnc/FjRGL0OgFtKXzMGdb7qKjidLoWTw=; b=SGUpMOsoibd+grSs4DZrgSBYy/ZGyQj442W7EGF7pixl52xCTCSDiRtqDgJFIt3p07 tKgMq8aIVcEbnZVO6OxdugxgPIgpSJ5eJ3UeR1oVGZK0p5jNjsOvVIRmriqym4d2xgH/ idYJf9KCssqu3kK/EmPDUbNO6R+6YT8FETqE8= 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=Hk17H4nlIgaxnc/FjRGL0OgFtKXzMGdb7qKjidLoWTw=; b=cUcRndwBnffb25t5Ato6Mr6doGBICXG0rxrspw7bZidfNU54MhYzxzOB25IxYzzybn xUllOr8vyS1l2ZF2TDgh4zZCFr2bNTR1mVqr5kLkXGRRcXQ5Ry+TjR9s3rhdMU3ezt8V ODw24pYcBgH+WOCc9rvQQ7igqwct3wXlUkpmnlU3talxSRiX7YJdSTnpSe9+xm1zrHDF B5TspcUJ5OYdHYS3L2w8x7BO8QbSZGzpRWmCoBBkvivF3y8/uC+NxdhhDlJCnONJLdj1 +TfZuTlVZ3d/6xA8Tn7/xCw3pMaiw76hoBLcntSKQQjf9B+MncKzLCMeVjuyObEKwNm5 uNAQ== X-Gm-Message-State: ALQs6tAAiK1DVVX9kzPmAO3Kxi8iPOOnSAqQgta2QWUgck7nsORQM7bm TVOvxz+EL4mBEpYbe60uwDFThw== X-Received: by 10.98.101.131 with SMTP id z125mr26862764pfb.208.1524637636253; Tue, 24 Apr 2018 23:27:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 186sm30043693pfe.109.2018.04.24.23.27.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27: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 Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 06/11] arm64: kexec_file: allow for loading Image-format kernel Date: Wed, 25 Apr 2018 15:26:24 +0900 Message-Id: <20180425062629.29404-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/arm64/include/asm/kexec.h | 50 ++++++++++++++++ arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/kexec_image.c | 79 ++++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 1 + 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/kexec_image.c -- 2.17.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e4de1223715f..3cba4161818a 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -102,6 +102,56 @@ struct kimage_arch { void *dtb_buf; }; +/** + * struct arm64_image_header - arm64 kernel image header + * + * @pe_sig: Optional PE format 'MZ' signature + * @branch_code: Instruction to branch to stext + * @text_offset: Image load offset, little endian + * @image_size: Effective image size, little endian + * @flags: + * Bit 0: Kernel endianness. 0=little endian, 1=big endian + * @reserved: Reserved + * @magic: Magic number, "ARM\x64" + * @pe_header: Optional offset to a PE format header + **/ + +struct arm64_image_header { + u8 pe_sig[2]; + u8 pad[2]; + u32 branch_code; + u64 text_offset; + u64 image_size; + u64 flags; + u64 reserved[3]; + u8 magic[4]; + u32 pe_header; +}; + +static const u8 arm64_image_magic[4] = {'A', 'R', 'M', 0x64U}; + +/** + * arm64_header_check_magic - Helper to check the arm64 image header. + * + * Returns non-zero if header is OK. + */ + +static inline int arm64_header_check_magic(const struct arm64_image_header *h) +{ + if (!h) + return 0; + + if (!h->text_offset) + return 0; + + return (h->magic[0] == arm64_image_magic[0] + && h->magic[1] == arm64_image_magic[1] + && h->magic[2] == arm64_image_magic[2] + && h->magic[3] == arm64_image_magic[3]); +} + +extern const struct kexec_file_ops kexec_image_ops; + struct kimage; extern int load_other_segments(struct kimage *image, diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 2f2b2757ae7a..1e110aa571dd 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -50,7 +50,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..4dd524ad6611 --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,79 @@ +// 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 + +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 ((kernel_len < sizeof(*h)) || !arm64_header_check_magic(h)) + 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 kexec_buf kbuf; + struct arm64_image_header *h = (struct arm64_image_header *)kernel; + unsigned long text_offset; + int ret; + + /* 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.memsz = le64_to_cpu(h->image_size); + text_offset = le64_to_cpu(h->text_offset); + kbuf.buf_align = SZ_2M; + + /* Adjust kernel segment with TEXT_OFFSET */ + kbuf.memsz += text_offset; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out; + + image->arch.kern_segment = image->nr_segments - 1; + image->segment[image->arch.kern_segment].mem += text_offset; + image->segment[image->arch.kern_segment].memsz -= text_offset; + image->start = image->segment[image->arch.kern_segment].mem; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->segment[image->arch.kern_segment].mem, + kbuf.bufsz, kbuf.memsz); + + /* Load additional data */ + ret = load_other_segments(image, initrd, initrd_len, + cmdline, cmdline_len); + +out: + 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 b3b9b1725d8a..37c0a9dc2e47 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -23,6 +23,7 @@ static int __dt_root_addr_cells; static int __dt_root_size_cells; const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Wed Apr 25 06:26:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134229 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp471083lji; Tue, 24 Apr 2018 23:27:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+vRNYxrflVwpWwqZ0BvHbSJ6dL/WcvSjBalyriGM6N3hRK/IzvIn/RyVfp3q3TsW7Qmjt2 X-Received: by 2002:a17:902:9898:: with SMTP id s24-v6mr27982684plp.51.1524637649412; Tue, 24 Apr 2018 23:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637649; cv=none; d=google.com; s=arc-20160816; b=mBiWUyAemL1WlTR9rUMQzbASbK0cH9k3kdliBqO3U/bSwm12n6oW6IoGDRoSsHuFuJ fIpk5NrWE6NYe0/maFLtCGJKKbTmmDX/Lp70LNkwXYGwTBynOM6x1MGJZZUH0n0Zdc3z 8jcn2SDE9TxSoRFFgXh8v5KBtNr1qt9iQnVXf+aQtQVqn/oxpErK42YNhLD84eniBKTT tYnDkM5csVNHxVMK2JxhxDjoenVkuTfwOkyT/xPuV60XSawTpzUtG7E57p6+ZTn6NPxx WfoepE/lykuPdR8JfdZdh+pyQhQNW+9b4nlg0nWfhIBlXhmj3NOG06fewb7iwB1DuGsG 8PVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=1HOJ4FLtWn5Gl/C7ILeWwijgFK2VEnPuy9cmAZsgoPw=; b=e0cRvmjA78XTPYni67egK8xvEmzcRTgXWGAA9+Y+eb9Uc6+snpyU4SNlFgQUdL6X7e 3VaqkCxMmiNNVVARVo9fFOe1iMT8PkuGzKKvIuamMH1ejT9luQLQQ8AIMFJHIvwpY9ac KzM85n8Opkjjoy8z+WaYwzaJ6gUH+t6A39Ti7zlCo+NMQhnsakSm1wdz5rW+mLtlz40C Cprq17AwubqlkdiboKQa7HQKUKPZjaRJk2oQmzLCvAEAjdhD688FbDz895PPDTp0J1DF /Gztd4dIX1nd4dmalqKXY9jIwkNxsfX8vHMoXzep812S6b0ztwjOlAIFxbw5qfzIaZGJ py3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Re9sIlVF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11-v6si16032873plk.434.2018.04.24.23.27.29; Tue, 24 Apr 2018 23:27:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Re9sIlVF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751537AbeDYG10 (ORCPT + 29 others); Wed, 25 Apr 2018 02:27:26 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33683 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751274AbeDYG1V (ORCPT ); Wed, 25 Apr 2018 02:27:21 -0400 Received: by mail-pg0-f65.google.com with SMTP id i194so12607138pgd.0 for ; Tue, 24 Apr 2018 23:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1HOJ4FLtWn5Gl/C7ILeWwijgFK2VEnPuy9cmAZsgoPw=; b=Re9sIlVFXz55O4a+edz2gwoWv0yK/f+6y87kS0HOTppfMDfKtLiQ6xNmLX+Mg6ChZ3 v0qm731u7T5L2CbwaY1Fc082q/0H9xiNVhXl4QWrmw6cH6t9Vb52h9nwJBKHZfHoCmpi ToK9skFW0LuCHuZfAm35tpoi1i17+FNRN9toY= 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=1HOJ4FLtWn5Gl/C7ILeWwijgFK2VEnPuy9cmAZsgoPw=; b=BXKmgJpg9voCO75WpGtdMJns+vdGep5ZEGlLwTd8rKHoorpZ8blUMgnw6+03aPeBpU UDlH8Q5UmcqBDLvea9pLJjL3Ges/AQKwCyHouwrwR5CTN+SWIf4bnvvRTS71GTcJnL3S 500ZJxeIyPyFxL/31262iNFgG1dnLhooV8ikBFU3jlOZvnf9Tdkx+mz4Zkq71U3puq6b Plgva/ZWeh9UYdo/F19GGQLUH1sPhaHzm1ezKJRYOQOtd58/QN0rwH1KR5LbmSeAtToE Ta8XOQhM1P5oFh+CPVZTsG1AJHGBlzUj3OiLv/aF9Zs+oEMz0Rf+VyuyqhPI8vbP4sYY XPeQ== X-Gm-Message-State: ALQs6tAGES9HNEPpE8weK3xrtTpvUxCAEjsG5hA4Ga2Thrv6Wr9knxeu yCf0QedIq7/05Yo7MYwgRizyog== X-Received: by 10.101.66.199 with SMTP id l7mr23203786pgp.335.1524637639953; Tue, 24 Apr 2018 23:27:19 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t64sm32000852pfi.34.2018.04.24.23.27.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27:19 -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 Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 07/11] arm64: kexec_file: add crash dump support Date: Wed, 25 Apr 2018 15:26:25 +0900 Message-Id: <20180425062629.29404-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 repsectively 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 --- arch/arm64/include/asm/kexec.h | 4 + arch/arm64/kernel/kexec_image.c | 9 +- arch/arm64/kernel/machine_kexec_file.c | 202 +++++++++++++++++++++++++ 3 files changed, 213 insertions(+), 2 deletions(-) -- 2.17.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 3cba4161818a..77f05bcf6a42 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -100,6 +100,10 @@ struct kimage_arch { int kern_segment; phys_addr_t dtb_mem; void *dtb_buf; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_sz; + unsigned long elf_load_addr; }; /** diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index 4dd524ad6611..2b3baf7285e0 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -39,8 +39,13 @@ static void *image_load(struct kimage *image, /* Load the kernel */ kbuf.image = image; - kbuf.buf_min = 0; - kbuf.buf_max = ULONG_MAX; + if (image->type == KEXEC_TYPE_CRASH) { + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + } else { + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + } kbuf.top_down = false; kbuf.buffer = kernel; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 37c0a9dc2e47..ec674f4d267c 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -17,6 +17,7 @@ #include #include #include +#include #include static int __dt_root_addr_cells; @@ -32,6 +33,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb_buf); image->arch.dtb_buf = 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); } @@ -76,6 +81,78 @@ int arch_kexec_walk_mem(struct kexec_buf *kbuf, return ret; } +static int __init arch_kexec_file_init(void) +{ + /* Those values are used later on loading the kernel */ + __dt_root_addr_cells = dt_root_addr_cells; + __dt_root_size_cells = dt_root_size_cells; + + return 0; +} +late_initcall(arch_kexec_file_init); + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +static int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static bool cells_size_fitted(unsigned long base, unsigned long size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((__dt_root_addr_cells == 1) && (base >= (1ULL << 32))) + return false; + + if ((__dt_root_size_cells == 1) && (size >= (1ULL << 32))) + return false; + + return true; +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + u32 val32; + + if (cells == 1) { + val32 = cpu_to_fdt32((u32)val64); + memcpy(buf, &val32, sizeof(val32)); + } else { + memset(buf, 0, cells * sizeof(u32) - sizeof(u64)); + buf += cells * sizeof(u32) - sizeof(u64); + + val64 = cpu_to_fdt64(val64); + memcpy(buf, &val64, sizeof(val64)); + } +} + +static int fdt_setprop_range(void *fdt, int nodeoffset, const char *name, + unsigned long addr, unsigned long size) +{ + void *buf, *prop; + size_t buf_size; + int result; + + buf_size = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + prop = buf = vmalloc(buf_size); + if (!buf) + return -ENOMEM; + + fill_property(prop, addr, __dt_root_addr_cells); + prop += __dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, __dt_root_size_cells); + + result = fdt_setprop(fdt, nodeoffset, name, buf, buf_size); + + vfree(buf); + + return result; +} + static int setup_dtb(struct kimage *image, unsigned long initrd_load_addr, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len, @@ -88,10 +165,26 @@ static int setup_dtb(struct kimage *image, int range_len; int ret; + /* check ranges against root's #address-cells and #size-cells */ + if (image->type == KEXEC_TYPE_CRASH && + (!cells_size_fitted(image->arch.elf_load_addr, + image->arch.elf_headers_sz) || + !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_len = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + if (image->type == KEXEC_TYPE_CRASH) + buf_size += fdt_prop_len("linux,elfcorehdr", range_len) + + fdt_prop_len("linux,usable-memory-range", + range_len); + if (initrd_load_addr) buf_size += fdt_prop_len("linux,initrd-start", sizeof(u64)) + fdt_prop_len("linux,initrd-end", sizeof(u64)); @@ -113,6 +206,23 @@ static int setup_dtb(struct kimage *image, if (nodeoffset < 0) goto out_err; + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_range(buf, nodeoffset, "linux,elfcorehdr", + image->arch.elf_load_addr, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_range(buf, nodeoffset, + "linux,usable-memory-range", + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop(buf, nodeoffset, "bootargs", @@ -148,17 +258,109 @@ static int setup_dtb(struct kimage *image, return ret; } +static int get_nr_ranges_callback(struct resource *res, void *arg) +{ + unsigned int *nr_ranges = arg; + + (*nr_ranges)++; + return 0; +} + +static int add_mem_range_callback(struct resource *res, void *arg) +{ + struct crash_mem *cmem = arg; + + cmem->ranges[cmem->nr_ranges].start = res->start; + cmem->ranges[cmem->nr_ranges].end = res->end; + cmem->nr_ranges++; + + return 0; +} + +static struct crash_mem *get_crash_memory_ranges(void) +{ + unsigned int nr_ranges; + struct crash_mem *cmem; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + walk_system_ram_res(0, -1, &nr_ranges, get_nr_ranges_callback); + + cmem = vmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges); + if (!cmem) + return NULL; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + walk_system_ram_res(0, -1, cmem, add_mem_range_callback); + + /* Exclude crashkernel region */ + if (crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end)) { + vfree(cmem); + return NULL; + } + + return cmem; +} + +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + int ret = 0; + + cmem = get_crash_memory_ranges(); + if (!cmem) + return -ENOMEM; + + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + + vfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, char *initrd, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len) { struct kexec_segment *kern_seg; struct kexec_buf kbuf; + void *hdrs_addr; + unsigned long hdrs_sz; unsigned long initrd_load_addr = 0; char *dtb = NULL; unsigned long dtb_len = 0; int ret = 0; + /* load elf core header */ + if (image->type == KEXEC_TYPE_CRASH) { + ret = prepare_elf_headers(&hdrs_addr, &hdrs_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + goto out_err; + } + + kbuf.image = image; + kbuf.buffer = hdrs_addr; + kbuf.bufsz = hdrs_sz; + kbuf.memsz = hdrs_sz; + kbuf.buf_align = PAGE_SIZE; + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(hdrs_addr); + goto out_err; + } + image->arch.elf_headers = hdrs_addr; + image->arch.elf_headers_sz = hdrs_sz; + image->arch.elf_load_addr = kbuf.mem; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_load_addr, hdrs_sz, hdrs_sz); + } + kern_seg = &image->segment[image->arch.kern_segment]; kbuf.image = image; /* not allocate anything below the kernel */ From patchwork Wed Apr 25 06:26:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134230 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp471139lji; Tue, 24 Apr 2018 23:27:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx49E5WKuomkSqD3sKUz2gg7dbBiciupCbCTlWOjVBnvk82JZvzsg9+zJiQhFJwsW7AXQ8n5D X-Received: by 10.101.100.193 with SMTP id t1mr18254479pgv.406.1524637652912; Tue, 24 Apr 2018 23:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637652; cv=none; d=google.com; s=arc-20160816; b=tNQFm5RmkqPAIGJjGaOt28gWvwc+JJOC3ijsSXzzSK1Ro4jaOgg7k+4q5U23YoJ0q2 SeT9lvTKVNgGWNBexrxYalg4yEaQc0SefXedL5mUvOn7vm2Bfqi0oejuoB9z+cyPrHXg mmkIBxgeJG8VQgFco9boXkiCoght2Rqmmnue2Uel9mqGmWK2OR+BRtfjt6M1rVmfzB4c qDWTiBp/gZFsehLkivVLsN68xzLLiORfJFa9U46KYUlr8M35hJEe2pxbqA7Q+pC4P+W4 W/Va2yDXVgdBtUax7VIQaBAm0IkE0e/FT02jDFVdIae5evyTwknxzWO4vGDC3U2tfGjA WcaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=GkSdrpqMLsrzG/RGdV+Y7IpVgMY9NzEc/8I04UUjrT0=; b=dLtJhVyFugWEWYdeNW6O/2rc3qE+FpbHbwsrvcWxS5OdE6bpExGo674sFZjE6ya/xn 4Aolh3QnZsDaXpKUkij6kJ2EV5cQ0LIjSQyyRJTchgag6gCj62t7tyScJFKbO/XrH4Kv 38IGHH8MkAQQclmL4Vu5g88jF9VjnsrDAutt1Wnf3rgjxOURGF8DoZ4KGCB2caBxwslB nKLiQ89RiS+HjfGuNoFeyrTwozTUsAo+gla9v2VV1qFzIzxv/D24kd9Q9aQx9eyAmPg0 v+pif+dVk49H48avaDTiJWUAT1aPjWbXw/g3UZXQTp8JxfitShdbM7KA6bYC7hwtR6+5 dhYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VOjZm36S; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z73si10300366pfj.197.2018.04.24.23.27.32; Tue, 24 Apr 2018 23:27:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VOjZm36S; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751570AbeDYG13 (ORCPT + 29 others); Wed, 25 Apr 2018 02:27:29 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:40749 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbeDYG1Y (ORCPT ); Wed, 25 Apr 2018 02:27:24 -0400 Received: by mail-pf0-f193.google.com with SMTP id f189so5205950pfa.7 for ; Tue, 24 Apr 2018 23:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GkSdrpqMLsrzG/RGdV+Y7IpVgMY9NzEc/8I04UUjrT0=; b=VOjZm36SRXzXbYO/8KyRlUoZEFFYYCnpYbfOU7Bz6S2w1Ssye66FD7SyMosILFkx60 vqZIcRIY3Ad5zAq9j6DH1QWk0z3jMjvF6MO9MiP9R982kwZ9i40RrGOkv1Y5Q30qBxyV 1swZT65iu9NnA9rJvMaD5YxyaKoUHv1C+25EM= 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=GkSdrpqMLsrzG/RGdV+Y7IpVgMY9NzEc/8I04UUjrT0=; b=T49mjRGIwMOZoN7vX7+ZcmDWKMZLurWMekfVWgW1QWESMGR/8Rb4+JX2fd1CD64UYf wvP6DyHb53AUpQDFIruTd8glG4Pinfw17z94OfBksYFnUEFkoKLHwycL5WxjB6Jk/BnL NaV/7h16T10MI0O+1EQqLcjQY7P+fjYeBxvM5J6WssMj5WSxzq2gAHyDkSC+GzNB3Maz ZN6DrLfPJZLN7F7HD+BcfN701V1O4kU/JdmpmUwUB80DOZOSGsct2ondgNxPZm4cDNry VRYkXDp4oS3BMKgAC3y388vRake8EIN84JtTcNYJz2loXq52E82oWOPD13LKifWqzgSb 8rZg== X-Gm-Message-State: ALQs6tDmaG+ZBmexD+c+ermIqQQ51SnXC9SncO1c0MChZe2bvZ0bfm+t 6s6wif9val4xaA/QJYfzIwMLcw== X-Received: by 2002:a17:902:ea:: with SMTP id a97-v6mr27213387pla.28.1524637643726; Tue, 24 Apr 2018 23:27:23 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h2sm32673918pfd.119.2018.04.24.23.27.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27:23 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 08/11] arm64: enable KEXEC_FILE config Date: Wed, 25 Apr 2018 15:26:26 +0900 Message-Id: <20180425062629.29404-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Modify arm64/Kconfig to enable kexec_file_load support. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Kconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.17.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index eb2cf4938f6d..d8f0dcdb8b96 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -847,6 +847,16 @@ 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 + select BUILD_BIN2C + 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 From patchwork Wed Apr 25 06:26:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134231 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp471204lji; Tue, 24 Apr 2018 23:27:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx49s9F5vQS4oioP9LqXqmImZXF8xvgj2hp8swik+zoQon7icLJ10bhpkqvItWdbIM8uWGdIR X-Received: by 10.99.95.5 with SMTP id t5mr22309503pgb.165.1524637657645; Tue, 24 Apr 2018 23:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637657; cv=none; d=google.com; s=arc-20160816; b=oKQSsqTe8hhohtGYfaXYBbhP/sBVsOxDhym8NGF7sNZEt1NW4K84KSQvIffk6wuUDq 2xwM4d4JvQsOjus6gC9OgMS34GqpPGp4JPcp3/j59ahL3r8CHMxvVFXtCDENdpU9edLg +OgEGsJUyvYsgmbA1mrui4zULoQvyVKOKYNEtv3cPQWcnueKVNKdmU8KR6ofSIfTg/3n 8CSv3fnDAB7aE807oeHfMa9pPMOi5xEhPEqgN+beCgQYpmaP+BPeP0XJ16NMPJKPaQ8E q2985f75f9+Xh6T3Nl3Bo7zlqJoDP0y5BMFXjrlG8JmYpsctuJ+JoBwzZ1IDwXIpwS7q ic2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=udBD3FA/hkAWhAoznOJdhSIXwaGNnm+w3oMPbyzv9VI=; b=ni2AfJwOR6Vsoh1+jxSbWm4Z4yl5BKl40SF9Bs+xjdzfwbQv3jsiWC4ryw19kDRZP/ VB6FX2Mti2KBJzuGjBhjS7KF0p7djNDw0y/d9skNHi1n9hDi7OMgExmvJl6Ct3WZLuNz PTlXjU4OcTE4adu5EJ6CzTeUzC9/V6+ZkgFo5q+2a+vHBX+5SC3OQQjtstzdT4tTp9Uy vWcb65Cze1BJd1teyJ4H2Jq+gW+bXuS3Y+gXVRPiWk4OpB6r1nDZAruM3yJ9wFgZ4FWk yL2mi4+F78s5gP1DUbXLcc1mJ4ALu9GguXTd+NAPc2ElhlhL/tcfYex7vvQwt/KKp3ik rRVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IG7WVibC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z73si10300366pfj.197.2018.04.24.23.27.37; Tue, 24 Apr 2018 23:27:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IG7WVibC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751613AbeDYG1f (ORCPT + 29 others); Wed, 25 Apr 2018 02:27:35 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:47079 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751538AbeDYG12 (ORCPT ); Wed, 25 Apr 2018 02:27:28 -0400 Received: by mail-pg0-f68.google.com with SMTP id t12so12597445pgp.13 for ; Tue, 24 Apr 2018 23:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=udBD3FA/hkAWhAoznOJdhSIXwaGNnm+w3oMPbyzv9VI=; b=IG7WVibC5KlgGNyjs5gTa0yNZCRx4QUZwwlgWyQkog+NJUtizsNhBwt+5DNtpj4+Mo JcMQZ8hwmgN3V7WDKLYmInlox37BmD3mu+702dtnR1KWw3S8EvuUhfeKeXcRJA9NeW+1 d5HLdmW5JG8La/LHfVO7t6U4ACKeJ0Tn5DUOA= 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=udBD3FA/hkAWhAoznOJdhSIXwaGNnm+w3oMPbyzv9VI=; b=BazxacZef/Mi2IYG0NgDX6iivM6uXTxm+zGFdd7W0z/Gooh/9CSVGHYisZf2aWVvuG EdLV8NnhESByIZdiIbk+sDH0KPKVGXTSBZHF/q3KBMHVI/dCiRsaQEkrz4ShujJZLsY5 WR7dGpeL5CrN09zwWgj8BknT0fJt4T8UyL6lWl8uTi8sXC+NzmwwLXGT6rAoepej0Pyc 6jFyNqYfAfiGR63/oXUnGpq7c0E3AYXeiz/wy+8ouDjUazpO7VHBCmpnrx6zG60X+neA Vgbsoq1dDktxQ6OCPrX453k/EVylgWibXAqwpQRB6VFDz2uXqZN/ff08CW+NsavhI2wG oY+A== X-Gm-Message-State: ALQs6tBpn7xuZwNATcPiqH8qn4orFOYcDEV0XKNU4vBSuFqOc9mW4mS6 IWzK+YIzLmaTWVhqgo6yFas5iA== X-Received: by 2002:a17:902:ba94:: with SMTP id k20-v6mr28065427pls.193.1524637647594; Tue, 24 Apr 2018 23:27:27 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w134sm33993496pfd.132.2018.04.24.23.27.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27:27 -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 Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 09/11] include: pe.h: remove message[] from mz header definition Date: Wed, 25 Apr 2018 15:26:27 +0900 Message-Id: <20180425062629.29404-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.17.0 diff --git a/include/linux/pe.h b/include/linux/pe.h index 143ce75be5f0..3482b18a48b5 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -166,7 +166,7 @@ struct mz_hdr { uint16_t oem_info; /* oem specific */ uint16_t reserved1[10]; /* reserved */ uint32_t peaddr; /* address of pe header */ - char message[64]; /* message to print */ + char message[]; /* message to print */ }; struct mz_reloc { From patchwork Wed Apr 25 06:26:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134233 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp471640lji; Tue, 24 Apr 2018 23:28:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/JWBV7O7bXHp9J0HBEHr0otYDcVSDqv8ueSqP5BM8McLUU1Oh6hWJUEszNHFEIGr3fzvgU X-Received: by 2002:a17:902:e8:: with SMTP id a95-v6mr27861192pla.274.1524637685612; Tue, 24 Apr 2018 23:28:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637685; cv=none; d=google.com; s=arc-20160816; b=WvI7xfsN8fU55Dgk+WLffw9Q+vldmttaP34OHWq6wZ69ZKcacjXYgfxb7cJQKVc/PG esC9lwi0L28vL++nJYmUi6e0Ri1qiv1xGk7wA0t1rMdn/R1htUdYf2G26LJ1k//lKxHZ cQ1tgm90NRD0im4+PXgpTHnRC4DUYDwrkM0tvG6KLyGaNonSyVvgQXv4xOcvrljBgvOj Nfuzel7dHmhQZpSCE1iqjjYpc6RKmm291AjXM9ZS6Q8oxjdHM48+sK73Ljitpl+cjMEv AEtw7NXX8nXi0XhVKq26eudBdiri/DTL5v+jEaFV+Ac1CjiplVdP2TJbYTtva3ijI3RS KgxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Tp+ZjioygloSn7ojZ/L8ExtDAHDB6CBDOV7WCLXOlSA=; b=HnI0z6sXaa1mVEnX/sanWfNvA0RJxB4iWcg3wlt2HHmTLCwEjCS440Lh1COO+MBtZm RNTCbbuaFSdFL1dY6IBsWQLuEmkaOo9bMGgUk70qeBFpZ9H8hYrG+dwZwz1ZtlTrMS2D MMlEgWWwwyCdU9f1LNyNUFodiiBabRnn4p8ochYA3zNCaiBUAEw9y/gwpL50UGiLroub o1hwvEGjNIe3vNE4xvER74IAgus7capifu6Li6yKIw56/kdNzFkElK4C9HctTPLXhQV0 olK2GGdCYWxq5QtgDP8iHeJiFsqnLEv37ij664zWSPxVZTMgQnlpMM4uHSHzzNxmqFXk sqRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=itskFRdx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a23si11316463pfh.295.2018.04.24.23.28.05; Tue, 24 Apr 2018 23:28:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=itskFRdx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751822AbeDYG2B (ORCPT + 29 others); Wed, 25 Apr 2018 02:28:01 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:46269 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751573AbeDYG1b (ORCPT ); Wed, 25 Apr 2018 02:27:31 -0400 Received: by mail-pf0-f195.google.com with SMTP id h69so14312181pfe.13 for ; Tue, 24 Apr 2018 23:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Tp+ZjioygloSn7ojZ/L8ExtDAHDB6CBDOV7WCLXOlSA=; b=itskFRdxXdpVdmZbHFFCQj3l/1j9tBslwRvw0fmgpBor2YXdtoRv6L5JqrN3IMi8R+ ODqRXKa66DPkk9ZDrjhYEc2DQgphOSeLKLPe5vg1/T8FMp9b79wVI//AswN+ix6b9jd1 SQc2dUD+xOcvIrtIuV0j2gKoQsnJzwyCDiVBg= 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=Tp+ZjioygloSn7ojZ/L8ExtDAHDB6CBDOV7WCLXOlSA=; b=KkP3DfeGXSmFJ/rkUHgqZrHf8viG2c8cOE40qs20vt5/GhpkdOmzxHHVodZoaRc6am fea7Sggywukx6VRzNZ03g3OcsF0ZskdQGECsGciyCgW3t2jjbjbNHfYHyjyNLpFzgGv2 VrGRo2ilt0a1omUiYxg6iJsd/kqVOiqwn9mkagtHj7/9L2WFkaZXRTSioMs5LUmno3tp HQSa3Glx/0ZL8qRk7MPzbTOdbldiPNLWsbPrRv77DoWBjq1RV3VG4mT/F9xbpnAlQv80 izJCRkrCZGNZMPM04Z8YMVQO/jGzWH4A5I7YSLXW2TCBTQkzNnlNdCDhbEXaGNGBmhAY Syjw== X-Gm-Message-State: ALQs6tAv2usgJQzqFhbpC1DAd5uTUQwWOV1khj6Z8DVI9EaNLWVLlUWl 60FyQX1LKG3wWjtUgf/4TajouA== X-Received: by 2002:a17:902:20eb:: with SMTP id v40-v6mr27843684plg.277.1524637651318; Tue, 24 Apr 2018 23:27:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l3sm34094124pfg.49.2018.04.24.23.27.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27:30 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 10/11] arm64: kexec_file: add kernel signature verification support Date: Wed, 25 Apr 2018 15:26:28 +0900 Message-Id: <20180425062629.29404-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/include/asm/kexec.h | 16 ++++++++++++++++ arch/arm64/kernel/kexec_image.c | 15 +++++++++++++++ 3 files changed, 55 insertions(+) -- 2.17.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index d8f0dcdb8b96..5c772601840d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -857,6 +857,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 "Image signature verification is missing yet" + 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/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 77f05bcf6a42..891f2484969d 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -133,6 +133,7 @@ struct arm64_image_header { }; static const u8 arm64_image_magic[4] = {'A', 'R', 'M', 0x64U}; +static const u8 arm64_image_pe_sig[2] = {'M', 'Z'}; /** * arm64_header_check_magic - Helper to check the arm64 image header. @@ -154,6 +155,21 @@ static inline int arm64_header_check_magic(const struct arm64_image_header *h) && h->magic[3] == arm64_image_magic[3]); } +/** + * arm64_header_check_pe_sig - Helper to check the arm64 image header. + * + * Returns non-zero if 'MZ' signature is found. + */ + +static inline int arm64_header_check_pe_sig(const struct arm64_image_header *h) +{ + if (!h) + return 0; + + return (h->pe_sig[0] == arm64_image_pe_sig[0] + && h->pe_sig[1] == arm64_image_pe_sig[1]); +} + extern const struct kexec_file_ops kexec_image_ops; struct kimage; diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index 2b3baf7285e0..7c11beefe65f 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -24,6 +25,9 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) if ((kernel_len < sizeof(*h)) || !arm64_header_check_magic(h)) return -EINVAL; + pr_debug("PE format: %s\n", + (arm64_header_check_pe_sig(h) ? "yes" : "no")); + return 0; } @@ -78,7 +82,18 @@ static void *image_load(struct kimage *image, return ERR_PTR(ret); } +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG +static int image_verify_sig(const char *kernel, unsigned long kernel_len) +{ + return verify_pefile_signature(kernel, kernel_len, NULL, + VERIFYING_KEXEC_PE_SIGNATURE); +} +#endif + const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif }; From patchwork Wed Apr 25 06:26:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 134232 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp471288lji; Tue, 24 Apr 2018 23:27:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx48wKe+wt9Hn1nv0z8POQK10sJBK24PL93IgJFwhLIjVzsjbm4tQg30KpyquWc4lGlhA7N4M X-Received: by 10.98.87.150 with SMTP id i22mr26998627pfj.119.1524637663047; Tue, 24 Apr 2018 23:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637663; cv=none; d=google.com; s=arc-20160816; b=dpUXQUNEAQlO7LPspjLUBCrpVASycpDNbtY2VvZUmBrFKVeaSRfqXZynQchga98Y2n sAgaYHLKNvX3E4LpBlv+fcNZ4HrE5t7qoxGdQx+EVC/qxsCTqkd8F6MKtx7SYrWfZmC9 5xWx25+7oyaqYQvg4bSATMbOzaiM5ksUBFm4R+a7F9rsY9Z8lyNqAg/P8QLQhWUTyNZ8 B890edr+HF2kgYERWLDOWhAVfAf4wS9pUJSRWQHSZExEVUaOVuqdUWzkUwYAF+a1Vi29 ODA1YljCFlbhuIsZwBS+ixmtEf4oS/CAbs38JPCDT4SAHYP9+R3ejo6Q9fmjx+8lZShL VMLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=jBK3ptBP+kuxlmMWHAiBOcRa6D76/Wey0R++OHp+zjo=; b=JtT6Ew5o+ydkeeXtf6LeCS4Vof3G9uog8YcUxYBEGcAageGEUWdo5hBIhUe64epB6T 3ewVAFVv2hmO9gUsTVXPu8DH//WdzeixvpJJDczIu1liLLyxa4OpkukZLC7J7m7MS5oo XVs2qbfSXXLp8DaJYj8PQcr3d2ZgdjxhX9WX9jIDHv+yB7eh4fhD4J9MkR5e6ShxIGL7 FL7Ga9xSfHqczJzqeteiYXkNXw6BNnaortSmUvYwqe57PY6WuQ0WRvEOfiaJhjGKzdp+ D6E+Hgc1vBQ6dnWw0DNEk706+69/6842WJFsEk8ZzKWVQvENN/h2o+Aagi4fWoEySAJe /1Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LQV1RFpf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a23si11316463pfh.295.2018.04.24.23.27.42; Tue, 24 Apr 2018 23:27:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LQV1RFpf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751683AbeDYG1k (ORCPT + 29 others); Wed, 25 Apr 2018 02:27:40 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36294 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751538AbeDYG1f (ORCPT ); Wed, 25 Apr 2018 02:27:35 -0400 Received: by mail-pg0-f66.google.com with SMTP id i6so12609124pgv.3 for ; Tue, 24 Apr 2018 23:27: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=jBK3ptBP+kuxlmMWHAiBOcRa6D76/Wey0R++OHp+zjo=; b=LQV1RFpfWihgSWvjd4LkN4ClTBNu1yJrc0cOx7pJpL2g03gGuBSjVdJa2MC4SsY89E 8k677THLK5jU6Ih9tCqDUQdfSix/BAAB4DgGRuDf473/VYmxOG2V2sPgUU8C/pw2jfMc T448EKBnTcFZ63X4iKxLX7n00RXTXo96Mvwwg= 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=jBK3ptBP+kuxlmMWHAiBOcRa6D76/Wey0R++OHp+zjo=; b=tKSVvBghJccJ4HuQP8m07FWWpGV5hYuZYc9kDTI6qwyU83bYnUIq+/+AtUcLCUSTSm 8tsFeq8WfLZ28C5WdmE0hVaSVNhJtmSChzP/2+HzySabqIJL1kYmiNqJ+P+W0JwjKug4 0f2qjJacfMWKYlKTLFh7v6IpTeT2u4U3DCBNNA0u5Lneg+667eOr2h2R6woroY6spsX7 eD1YBJlytScsHxF9YCI42qPK/6bMBrs4zNiOrZzdjzPGy1o0qRaEVr1quz0QaDG8fpNF UmbmBMu0RT9yEAZaEIC2YgVnMACaAn7oORiiKkRuMk7P2G3V1ZK5701dCcPBtWulfwED 5FTQ== X-Gm-Message-State: ALQs6tBTnF3w7kK9ng0N2r8ApzSU1jbjBQSQ5FmCM2AOfIuNznSp5RJc 8Li2JXaiutG5TZuhlB1yuTwWxg== X-Received: by 2002:a17:902:2924:: with SMTP id g33-v6mr25575162plb.26.1524637655330; Tue, 24 Apr 2018 23:27:35 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v16sm8888380pfk.164.2018.04.24.23.27.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27: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 Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v9 11/11] arm64: kexec_file: add kaslr support Date: Wed, 25 Apr 2018 15:26:29 +0900 Message-Id: <20180425062629.29404-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding "kalsr-seed" to dtb enables triggering kaslr, or kernel virtual address randomization, at secondary kernel boot. We always do this as it wll 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 | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.17.0 diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index ec674f4d267c..762f9102899c 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 @@ -246,6 +247,12 @@ static int setup_dtb(struct kimage *image, goto out_err; } + /* add kaslr-seed */ + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop(buf, nodeoffset, "kaslr-seed", &value, sizeof(value)); + if (ret) + goto out_err; + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;