From patchwork Fri Sep 7 07:56:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146190 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp859766ljw; Fri, 7 Sep 2018 00:57:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbmaVH3R4SMKyIN/i7KqaYoPOYYlDgtHs6xfqf4yxHOLj/iS3hLOyAIAF+LyYYCr4WAMrw0 X-Received: by 2002:a63:e255:: with SMTP id y21-v6mr6929229pgj.160.1536307040333; Fri, 07 Sep 2018 00:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307040; cv=none; d=google.com; s=arc-20160816; b=XZZmJgmaw4up8SY9GKfzinDU5Xc9uDfT1g3BgfE6m4hca11AMNGlHIn0PfIgdYpKQ3 uWEWUh7E+281WJlrwgq9OUIzRF6PIqJk0LSQqg+9AYMrAgtxGHMBfQmk9jt/UOp8Gt/5 1rJD11SAEZkxsTscjxzjzD+rO3B/sREEleo5tG67TQanxWu5gF0kTSZGzV8m5IZcYzF+ aepI8Kzith/5N0ETQYFlzbZ4ChHJ6aCh18bRKIp84XCqpVwKRketEWeNpur2RcSxIQiT VMJQRufiXE+m1p9rqSbisBdsxoSfsV1wGhJJnaIBgXiGPQptZBbz5supgqxhDJDlkhVG xuqQ== 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; bh=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=Q00FtAUIgADHWJp6IFLF2Zn7HoKFJ2Z3jIb/UlTUW8yn4ThNKipWa7hQVOvuLfY3uk HyaPxcgTBFPu4NDfWBKxWuz3wI3jMFbxUy4mktyXzJfjIvcUWzL7eo4JwKrWmGypzJou DSir+3WO8TXiaAmM1XyMzDgwTgWk+qM8Tgy0uCke+BUF9GdW/XOTgW6VIe5Hb9IB0hf9 j8OPKWQSE8aKzOsa+/FmzVCpSIyhc1D3FaCrbsYf5ofVtaOlFQRWsNKPqGnl03OUM/kd utdvOf6VLL0LAuWNP/YCL/tDKl9iIdnoijiApr30+wSwrj5qB8N8ebnbi6hsO2yoaRzh GGxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vrs7iPZa; 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 x7-v6si7680254pgh.595.2018.09.07.00.57.20; Fri, 07 Sep 2018 00:57: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=Vrs7iPZa; 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 S1728013AbeIGMhA (ORCPT + 32 others); Fri, 7 Sep 2018 08:37:00 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33141 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbeIGMhA (ORCPT ); Fri, 7 Sep 2018 08:37:00 -0400 Received: by mail-pf1-f195.google.com with SMTP id d4-v6so6640154pfn.0 for ; Fri, 07 Sep 2018 00:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=Vrs7iPZaJs2lX7U8ETOMXsv5z2KiZmr2IZAgRk2mnxfHL1v2nrLT18bqKI8Eg8Uv5l 0Ik6D/GqZpiGZipS29hvfmytB2YBkFmVbfrny6kOaANMXudo3ez/gpzvTsJIuqqu9aJ4 PFJS+uH491XkCYfqNC5s1RlwuoiCpGd6aAf8A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=SBrLZaoRYBejJXITgcGkGRZy1FxtmPNvkzbqURyq3Ia8RC+tvEB38j0la6yAtgStcT SU0mI4V0/I6q5es5xCq6xCa+cjpzg/jbh5yACqcXymfTmpBC2ExoErImCGCCwfpdXQNS 5P/I258bwykLVjYNeCNbVHJ6ztwT4FzowyopYzJxfO+VpiZHMXkoYdImPE08wHWRK0ZL +hXvteNrxztCXevLdankjWyBqWfdhF0TYQz5eLYnuD4tNPd1HENcaG2cAzQY0fHqnJSL KvgN4CXtxjjmXGzkah3woWN+aJFSsyJ1iGLYW8wXdnR6ItS/+Y/gsFnHoLFcXNdX4cKL kg8w== X-Gm-Message-State: APzg51APP8PusU7RU+NrReJozVjUSwTO9kE3FmIJvvt6D7i+roZzYLKa AWYgtwG3D0lA+C8d+6EER4LbJQ== X-Received: by 2002:a62:1605:: with SMTP id 5-v6mr7168821pfw.11.1536307037247; Fri, 07 Sep 2018 00:57:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x9-v6sm12684384pfd.31.2018.09.07.00.57.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:57:16 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Fri, 7 Sep 2018 16:56:38 +0900 Message-Id: <20180907075653.4696-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> 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.18.0 diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index df4bedb9b01c..acea91e49523 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -736,9 +736,11 @@ __SYSCALL(__NR_statx, sys_statx) __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) #define __NR_rseq 293 __SYSCALL(__NR_rseq, sys_rseq) +#define __NR_kexec_file_load 294 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 294 +#define __NR_syscalls 295 /* * 32 bit systems traditionally used different From patchwork Fri Sep 7 07:56:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146191 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp859919ljw; Fri, 7 Sep 2018 00:57:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYs29hHKdRubi9xFwqA+xdo7ehWnRIoVwvbEXS+/qystCTYCgKWcq2NZ2E5moVXrIwhDMj0 X-Received: by 2002:a17:902:76c5:: with SMTP id j5-v6mr6713030plt.140.1536307053047; Fri, 07 Sep 2018 00:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307053; cv=none; d=google.com; s=arc-20160816; b=X5Se0GmYLpDPh94OCXEe9N5OAU7vpfkotEiweIOH5Q6yyUT9jAW3gIOi5LgHbLj34G +xAKNiMMh1YabvkB5LZhcvISQfFapUAkRkGMdwvAnSTrUTYCcCIi6tYHjAH/PdG5/dZc GdrMABrKFLaJN031fd7YUsKRpb0NzsDDMXOLijkKpuOgoJ8DsTFJdyj2rJAe6VMoge11 eHHpEgaANMwbAwVU+vbX43roG8h9vsPP2ISyDFSkWRq3eAns1KiKUIf9W7TztW3w5cg8 4BD8g+aoFRt/11/CInW/XDLMqId95ow67UaVywN9MFb4WdzhDyVFHsXBEuzOawVxL3sT Jxvg== 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; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=h6rucEoRTBeK2+d8S1cbUlueGxzS7pJTss9jFXqsEclPgP5C9KHGHsIKcozKohpcMx xHs9fp4lwS3+7H7xIYW82XM/g3GWKEtW1Y2JWcNBS6KibUQ66WeV5Tvix4f3AAB/n12T RN2YxygWM0D145Dxw+0n2kWjD6wQZnOrQtSrb8/Mn2+eFYw831WS52OctHFO8smtMDG2 caagUNIewp4x+LuhWgmAVF05FQk0j7EFDgcwMjz9yC4efB3z5i/O1xUhEBaG1zsoVety 92MsL2rYQzJfegcH6r+8zxiiJ3ZdsScUUJARIamtS/wGuoCNz7aFnIw1SADh3x/ILuJj hrGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QT7DAb1V; 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 x7-v6si7680254pgh.595.2018.09.07.00.57.32; Fri, 07 Sep 2018 00:57:33 -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=QT7DAb1V; 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 S1728027AbeIGMhO (ORCPT + 32 others); Fri, 7 Sep 2018 08:37:14 -0400 Received: from mail-pf1-f177.google.com ([209.85.210.177]:38870 "EHLO mail-pf1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727822AbeIGMhO (ORCPT ); Fri, 7 Sep 2018 08:37:14 -0400 Received: by mail-pf1-f177.google.com with SMTP id x17-v6so6638673pfh.5 for ; Fri, 07 Sep 2018 00:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=QT7DAb1VW3TTiSKno3oN+Ds4oOesrprs8hlPrzWly0uu8ex49FZI44yQkoCeR0AXlO rybOkj+45dEks0DMV0i9PMQOIkw6nwa/FjlkvSv4OVSPeAJXQMgs3oMmfIxbSwMei4TJ ARQiZQOCdCx9TdJVynK7qupICR+kH/Nwc/Ic8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=Er/4BgXdGvmt0dHg/LsU8lN36xXYcnydi4XKUWRQn4xi0tTrK1HjLXbZnmdnj0ycGk BGDuunAvyzyZWyaxWl2nwkdIHYVCr0MWPtlbY3P3EAeg92C9g/PmTKc6LBk9BPYX8JOb jKQ949pCSV0g9INW8GfG9cPbCd3qkZQjtjuSIVLFA4HYXyAt0WzMNiMB3HFUVK4sveIo 8JkYHUQRrZ9gb581mVlbVItx5HTEbXLniwU2fDZgOvnNeAx+AOZR+8BSVvYnNr9x3A7B IP65gcmvOZpB4tcvyrXP7QDdVV/i+V9PVIomTyUGSxl0XC41JNXWvO6R7zW01h6CnJY4 OcKQ== X-Gm-Message-State: APzg51DUTUna0lpif/uPz1f8nqCalHKtcvs7L3Tnlbc/HomQpYrEyN0j 93/YCDnQV6q7XqZCCbJXPOfU3Q== X-Received: by 2002:a63:555c:: with SMTP id f28-v6mr6968922pgm.37.1536307050029; Fri, 07 Sep 2018 00:57:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q26-v6sm12593771pfj.127.2018.09.07.00.57.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:57:29 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Fri, 7 Sep 2018 16:56:39 +0900 Message-Id: <20180907075653.4696-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> 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 Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- include/linux/kexec.h | 1 + kernel/kexec_file.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) -- 2.18.0 diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 9e4e638fb505..49ab758f4d91 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -143,6 +143,7 @@ extern const struct kexec_file_ops * const kexec_file_loaders[]; int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); +int kexec_image_post_load_cleanup_default(struct kimage *image); /** * struct kexec_buf - parameters for finding a place for a buffer in memory diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index c6a3b6851372..63c7ce1c0c3e 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -78,7 +78,7 @@ void * __weak arch_kexec_kernel_image_load(struct kimage *image) return kexec_image_load_default(image); } -static int kexec_image_post_load_cleanup_default(struct kimage *image) +int kexec_image_post_load_cleanup_default(struct kimage *image) { if (!image->fops || !image->fops->cleanup) return 0; From patchwork Fri Sep 7 07:56:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146192 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp860045ljw; Fri, 7 Sep 2018 00:57:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdazsHZib9IY6nqtg0S4dFAqiyi3tDVq8+wePMqEAhi5JqJd61YlO/EYnLlvTxqGZgxSkn4S X-Received: by 2002:a17:902:8e81:: with SMTP id bg1-v6mr6731099plb.129.1536307064494; Fri, 07 Sep 2018 00:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307064; cv=none; d=google.com; s=arc-20160816; b=gCpcY6xZYpY22fhJNr6e45bWJ5GfguncHg/vtwBcMK0A/z0KsMQyQoDnfhTT70JKSq kZZdvfVDjl30OO1ynk2dz8Y+w2IOfrIBjMYQ/4y4BHjExn96Yg4jPp/pQ+/LGhcG0D2e lfrwMpf3x47u/x12Jejq5HGIzLGV8b9/nh4EdyCyg1IGKdnTDzItXdD2VLavBP/25BjY 1+EOtBiO7YZkSMGJR5IfQk/J/+79SFT1txe1q6GCwye4WYgyEHKeBzYwNjgS8m3tXWgt KrGUrJT3g1HQeYTvq40tVvqgcFEwgW17o+wZJzDRsyXsSgx7m7GAAvDKT9HcwqRy66Xx +rkA== 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; bh=UFZdSzOBCDhCucMx9QLxaQGXbSUDnlXX6wiHP7BXxqU=; b=YjB5gKLJ2hZn2H7H431oFPKhkGZ0LvBX7phZFJckUp0uWs5nkMLEE/0OZ/UfFscwFY l7c2OMZRKdOYkHIZTlZGg2dK8vQinu6FJogjqJGfwrHDUELIXu0bsDNd4XrlMhbV9QKV 0UZPLE0TsjUa16MiYc1eBjHrqFilPp86nMFX1GGrRnhXKTyndmbEiODzK2xs2jrVkD9e 9XqmnvFx9sZ5mtH/Qbt3thQhZjVXRigtAHC/BljL22Y2w30Z9z4DA4A4X6f28Qawr6At TEvWsOOFvd8vrQYZ2HQvrGvMZUip116IFkAoCrBskQ6EFewkYdKxma1I5fiQs4kpjcpS sT7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NcvFPXdY; 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 e17-v6si6904562pgv.615.2018.09.07.00.57.44; Fri, 07 Sep 2018 00:57:44 -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=NcvFPXdY; 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 S1728039AbeIGMhY (ORCPT + 32 others); Fri, 7 Sep 2018 08:37:24 -0400 Received: from mail-pl1-f174.google.com ([209.85.214.174]:36477 "EHLO mail-pl1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727318AbeIGMhY (ORCPT ); Fri, 7 Sep 2018 08:37:24 -0400 Received: by mail-pl1-f174.google.com with SMTP id e11-v6so6231064plb.3 for ; Fri, 07 Sep 2018 00:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UFZdSzOBCDhCucMx9QLxaQGXbSUDnlXX6wiHP7BXxqU=; b=NcvFPXdYdZnDZNUVaQmm1LA4c2cwtD4jx3+WjEo8Va01rghMCP75wL98HCDEiKEYvr gafPvWw6Fq5vvgw1w6y3oLFWGyMnKqI+8chfWup9dmIjcNopmB2AM6xhsOdh1VACxtHz mIx7zRckOMd9qDkvOk9BiiHRfQ7z7O5wM+3TU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UFZdSzOBCDhCucMx9QLxaQGXbSUDnlXX6wiHP7BXxqU=; b=iJTGoeNKQrQwuQ1kqlDn3UrRe+i2AkIxteSpnCvC/ZTM+55cca1S9WGL77blOWNJ4s sd2pJgOZjzXGf6QvNvzyx8qctHTn/pWqXlLZqwbEqa1p7LpjwgKKMVV5GgExwt+rEVyB 2FQp83UilU5dIDoebu0T12jJ50N9+PS3fifdlQycWbXLbLpb2zJM10eGNYxWWt5mo4/j P6sTAzwLoRfBSYvrm7MMr6rhq52q+6Cysd6akZBitSNgbWkYtzm64rD595oSZ+dyu9dU Q03/gJ0ZeNLDl+0rCCcyj1euz0CaMc/y9KqjVY2v7hpUpG8i24MtNSXJZWscSI79B7oP 96rg== X-Gm-Message-State: APzg51ABur1QY9qvg90Z6kltfhU6sqmaCGsrPZYRojFlD1vpI7Jy3tlK qdw8M0gxs0CtzaH1rYq+klEFiw== X-Received: by 2002:a17:902:5a87:: with SMTP id r7-v6mr6601602pli.247.1536307060716; Fri, 07 Sep 2018 00:57:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f87-v6sm19872299pfh.168.2018.09.07.00.57.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:57:40 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Fri, 7 Sep 2018 16:56:40 +0900 Message-Id: <20180907075653.4696-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since s390 already knows where to locate buffers, calling arch_kexec_mem_walk() has no sense. So we can just drop it as kbuf->mem indicates this while all other architectures sets it to 0 initially. This change is a preparatory work for the next patch, where all the variant memory walks, either on system resource or memblock, will be put in one common place so that it will satisfy all the architectures' need. Signed-off-by: AKASHI Takahiro Reviewed-by: Philipp Rudo Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- arch/s390/kernel/machine_kexec_file.c | 10 ---------- include/linux/kexec.h | 8 ++++++++ kernel/kexec_file.c | 4 ++++ 3 files changed, 12 insertions(+), 10 deletions(-) -- 2.18.0 diff --git a/arch/s390/kernel/machine_kexec_file.c b/arch/s390/kernel/machine_kexec_file.c index f413f57f8d20..32023b4f9dc0 100644 --- a/arch/s390/kernel/machine_kexec_file.c +++ b/arch/s390/kernel/machine_kexec_file.c @@ -134,16 +134,6 @@ int kexec_file_add_initrd(struct kimage *image, struct s390_load_data *data, return ret; } -/* - * The kernel is loaded to a fixed location. Turn off kexec_locate_mem_hole - * and provide kbuf->mem by hand. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - return 1; -} - int arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section, const Elf_Shdr *relsec, diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 49ab758f4d91..f378cb786f1b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -145,6 +145,14 @@ int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); int kexec_image_post_load_cleanup_default(struct kimage *image); +/* + * If kexec_buf.mem is set to this value, kexec_locate_mem_hole() + * will try to allocate free memory. Arch may overwrite it. + */ +#ifndef KEXEC_BUF_MEM_UNKNOWN +#define KEXEC_BUF_MEM_UNKNOWN 0 +#endif + /** * struct kexec_buf - parameters for finding a place for a buffer in memory * @image: kexec image in which memory to search. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 63c7ce1c0c3e..0fcaa86219d1 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -534,6 +534,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) { int ret; + /* Arch knows where to place */ + if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) + return 0; + ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; From patchwork Fri Sep 7 07:56:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146193 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp860178ljw; Fri, 7 Sep 2018 00:57:55 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYvcoVeEQWZfb72QSMolxiE/ahwgRcbk1eT/k6epTyyCkYjLSHBg38sU9+inj8b+7QUOcF2 X-Received: by 2002:a17:902:280a:: with SMTP id e10-v6mr6622595plb.187.1536307075465; Fri, 07 Sep 2018 00:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307075; cv=none; d=google.com; s=arc-20160816; b=WSxM+pxl/vqeX+0sROtpuqqwsYbwWM+K6A0QKvBtfZMXBn6vZKISWSTZhuuVgV2b1m GXvREUhIKnCj2gKuRA0lybA3idgAQZDmw8nhC1xFhGaRWyeH4RwKO+ShJ0+qBAsy5GjO eQwGJOCcmKfdrx6c/VGGg/x+6hcoY4qVwIRaUNRuH0Irnihy8wpO43le67FYvh1h+Mjq 6fP4fT0G5iaBRETXVAA5/iuEcsuFJs+lJ88i1Q9Up6TN3Z5YSw/mEbsrEf9xAK5MtoS6 ReHOU5cht/smL1CDg84iVZUxkDOtST15dWtHgtCAfzF/XaIj/RWD+yxi7vjueSuw8MmV p0XQ== 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; bh=G9kYri4+HK/HIbj9APwd9ezqkNFakYGkDtWst37y2L8=; b=UNXUjHX5NUxuLnkchLW8r5hFOiprnMjoHgeDY/XgnoM7c9TWh5sLeJTC8qsmI9Nw23 IyxbD1x6BdRHk7lxvKo8ZmSQeHzzCi42nkzFT4/jrMwQlXs/yVbmtnX28cjl3YPDsWRn gW0ldbKXDRvAR1FiXh4HthqMFj3fXuP/9TkLN8/M6bKzvoC7WeysxCE7CHFeChhJnsXV 6cyVhxzFjws0DO21Rbr2bM/GsuKroZYQm7+XiVcklKfntBWqMuXQ0Yq7ZzG0h8rYU10W 4VqvPx9Atayor7s5r/i7JLpH6kVQFKkguL8BhZILFh2Q1sJD0RVJ1PIX/P9oisJXbZxb 5YHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kyWSI8rS; 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 e17-v6si6904562pgv.615.2018.09.07.00.57.55; Fri, 07 Sep 2018 00:57:55 -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=kyWSI8rS; 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 S1728052AbeIGMhg (ORCPT + 32 others); Fri, 7 Sep 2018 08:37:36 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43484 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbeIGMhg (ORCPT ); Fri, 7 Sep 2018 08:37:36 -0400 Received: by mail-pl1-f194.google.com with SMTP id h3-v6so2868935plh.10 for ; Fri, 07 Sep 2018 00:57: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=G9kYri4+HK/HIbj9APwd9ezqkNFakYGkDtWst37y2L8=; b=kyWSI8rSFfgNg0CEdOxp9hp3SeZ3F0IwNKz8gD27leOk0eBv2DgXp9yNqdfEAqn1UP 4kb2MFG4MO6IssGsYHWe8obziOcqhHFLc6rNqvr+zJ5qN9GSh7mWtIdiJEyb6YH+dIr0 PwV43kQpA1KwSwB1Gu1EIvYH6DntwxvoOs4wY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G9kYri4+HK/HIbj9APwd9ezqkNFakYGkDtWst37y2L8=; b=tblTHTE26wOImLVJSNcqtIhZDGFPiqf4ShqvvEsNsPJ7A7c+utsiH0BWz93xkCU4A+ pJkAriZUC+IF6dTEepCMZogUMzqBAwOdSLqWa2qG8pVXWVJXnisn8YzdCFmhqx8GYmZi GExF5XveBWmrv3TXlSptMlSdklKb70BQXX86foGwgJiQ6m1XR4Z5B2TjxD2whNysRnmn 6XMc5yGv13xHI7udiiPq1SA0DNEw6mnsJjsMn9edHuLyUdzKyNyNkdX9lp+3QEJuCrWO r0/yoXIsPKL+7zwebeb5MHTi86xx6xlT5SoBgwBcrN1yFtfmwl6Hp8XU2iBQ1fybnyDy +xMA== X-Gm-Message-State: APzg51BIvjFIVcZNgTKLX4lifHJkaAEMBfcopmA2HmVAxvdgh1NBq21A kk6efKI1DbTycrCbV/ruOAZUcA== X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr6659044pln.60.1536307072468; Fri, 07 Sep 2018 00:57:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y18-v6sm8498519pfl.90.2018.09.07.00.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:57:51 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 , "Eric W. Biederman" Subject: [PATCH v14 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Fri, 7 Sep 2018 16:56:41 +0900 Message-Id: <20180907075653.4696-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memblock list is another source for usable system memory layout. So move powerpc's arch_kexec_walk_mem() to common code so that other memblock-based architectures, particularly arm64, can also utilise it. A moved function is now renamed to kexec_walk_memblock() and integrated into kexec_locate_mem_hole(), which will now be usable for all architectures with no need for overriding arch_kexec_walk_mem(). With this change, arch_kexec_walk_mem() need no longer be a weak function, and was now renamed to kexec_walk_resources(). Since powerpc doesn't support kdump in its kexec_file_load(), the current kexec_walk_memblock() won't work for kdump either in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 ------------------- include/linux/kexec.h | 2 - kernel/kexec_file.c | 60 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 59 deletions(-) -- 2.18.0 diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index c77e95e9b384..0d20c7ad40fa 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, return kexec_image_probe_default(image, buf, buf_len); } -/** - * arch_kexec_walk_mem - call func(data) for each unreserved memory block - * @kbuf: Context info for the search. Also passed to @func. - * @func: Function to call for each memory block. - * - * This function is used by kexec_add_buffer and kexec_locate_mem_hole - * to find unreserved memory to load kexec segments into. - * - * Return: The memory walk will stop when func returns a non-zero value - * and that value will be returned. If all free regions are visited without - * func returning non-zero, then zero will be returned. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - int ret = 0; - u64 i; - phys_addr_t mstart, mend; - struct resource res = { }; - - if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, - &mstart, &mend, NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } - - return ret; -} - /** * setup_purgatory - initialize the purgatory's global variables * @image: kexec image. diff --git a/include/linux/kexec.h b/include/linux/kexec.h index f378cb786f1b..d58d1f2fab10 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -192,8 +192,6 @@ int __weak arch_kexec_apply_relocations(struct purgatory_info *pi, const Elf_Shdr *relsec, const Elf_Shdr *symtab); -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 0fcaa86219d1..370d7eab49fe 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -501,6 +502,55 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#if defined(CONFIG_HAVE_MEMBLOCK) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK) +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + int ret = 0; + u64 i; + phys_addr_t mstart, mend; + struct resource res = { }; + + if (kbuf->top_down) { + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + &mstart, &mend, NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } else { + for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, + NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } + + return ret; +} +#else +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#endif + /** * arch_kexec_walk_mem - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. @@ -510,8 +560,8 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) * and that value will be returned. If all free regions are visited without * func returning non-zero, then zero will be returned. */ -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) +static int kexec_walk_resources(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) { if (kbuf->image->type == KEXEC_TYPE_CRASH) return walk_iomem_res_desc(crashk_res.desc, @@ -538,7 +588,11 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) return 0; - ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); + if (IS_ENABLED(CONFIG_HAVE_MEMBLOCK) && + !IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback); + else + ret = kexec_walk_resources(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Fri Sep 7 07:56:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146194 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp860291ljw; Fri, 7 Sep 2018 00:58:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbA0ZkkZIDrqD2E0kB8SZv0M0jEA3t33fbjHHuprSGjLQ4NnZaJ9LvkF/IjpionIx4DvYmW X-Received: by 2002:a17:902:b282:: with SMTP id u2-v6mr6491525plr.123.1536307085881; Fri, 07 Sep 2018 00:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307085; cv=none; d=google.com; s=arc-20160816; b=nN6/XgeGuf/GOg7unBPEdH0wf2+Fs8j6ZPEKwe5+Av08IQgUmJrqnphr1WDpKMSQQG 20lfmBR2iKSq2hq3Kodg06rHdrPG69fUYquJ1S8bVq/tQyQ4molzadoXvHzXiaAqTmJn 7owepmDvTaGDgCwoUmIFyin7vF4imkER6d4OOZ7QbgMuqxpqUZf+kWaW0tWZeqyfEUag OlL1XIAmk/nIo/k+3uIypIcOZqbUXVdsL7mY8m3bN+PrR4LjKOFuN30u31ceM+Hdx9LB qeQDJMPsSSRnkuAISpDEjIclJ9npkxx2dL1q5gm0gO2AW8JppMACnMQgGnu8FlUyFks/ 64Hg== 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; bh=jeWHjhWZzqcn992r+CjxadoTg1glUklXZIt+KkbfGzY=; b=E4pMhGPkJIILhL5oz9kbfiXhgVdDU8hdx1ITcvP6UH7A0i+Mo/1LUR8EbP8B43HfrC t4jskEvWF5yp0HbAmk7rWbOsMwl+uF8x1bTFM1dprGAl7anXyx+5i7/j5+H8cD/m4Jp8 o2Cn/eGeiDzwRgh8Xb86if3phdv5kjlSfeIX6cwQJnq9clmRBE8Z+NvLkqT+De7VmdL0 DNuU5k+BxG+9RfZVkoLq/BfqFhjL2Zd8OLgTqmAIklxy2rWqngDh+OOWFCtM4oZ9hL2Q /fnpQw2BZX06IG+b+vksNMBbU/mc1Isio2M7h3W7RSaUnRwIs7i3povpLuf3x5VZK5kj Wmlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Iw6FIM/U"; 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 u10-v6si7057841plu.506.2018.09.07.00.58.05; Fri, 07 Sep 2018 00:58: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="Iw6FIM/U"; 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 S1728068AbeIGMhr (ORCPT + 32 others); Fri, 7 Sep 2018 08:37:47 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45087 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbeIGMhq (ORCPT ); Fri, 7 Sep 2018 08:37:46 -0400 Received: by mail-pf1-f193.google.com with SMTP id i26-v6so6615379pfo.12 for ; Fri, 07 Sep 2018 00:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jeWHjhWZzqcn992r+CjxadoTg1glUklXZIt+KkbfGzY=; b=Iw6FIM/UTbLuebPjiA4jQVIGzj1ZOSMVexZ11oWFVNDZ/ufvkYBdyX+BbPZ/5aYKuB r7XPHSCEgPMikmy/gv+Bo0F7HsfeRIQE/WRc+OOPgtR5GjEeC+1fc0e67z4kIxqGHvFI 9s44tc/wjbhJiYdjVD0GmiWIk9iV8rl4OPZWo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jeWHjhWZzqcn992r+CjxadoTg1glUklXZIt+KkbfGzY=; b=qRA9/44oUflzGjDqIM5WSRZMR/Je07E9yMra7flDKA7G+TRv99p8QIwA7v4f+xK8bW 8m7rZYYF7BUQZUibXIX4iKsQ/aPvgPbcmTbOR3wJOz2f3iF9f1arYzFjvg/+4EKS30// 0dg8R4AloVRmr4jWILhj7sdDfaUHG1L3mpJnoShIIcXz5aAw8JtRbVcjoXLm32W1VKU9 VJBVanpDA4931p8PT6vaM16lx8K3bY8UeESwRGAnBxALkojPmS/B3+V6doOhDX1GV8RT 4k15tadB75ar0h1FvfYSzc8k+y/wqtgTb4w7ShI5WnQvjzZSc95/RFIRzJnoIAyF8o05 5cdg== X-Gm-Message-State: APzg51AO3X+EUJPI2UVBadbOukE9DJTYvuLVeoln0erMQYuUwAMDlGq/ CFdjK/35gJW0J1SatBnbthBz5Q== X-Received: by 2002:a62:56d9:: with SMTP id h86-v6mr7152853pfj.229.1536307082476; Fri, 07 Sep 2018 00:58:02 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l185-v6sm18675979pga.5.2018.09.07.00.58.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:58:01 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Fri, 7 Sep 2018 16:56:42 +0900 Message-Id: <20180907075653.4696-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907075653.4696-1-takahiro.akashi@linaro.org> References: <20180907075653.4696-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In kdump case, there exists only one dedicated memblock region as usable memory (crashk_res). With this patch, kexec_walk_memblock() runs a given callback function on this region. Cosmetic change: 0 to MEMBLOCK_NONE at for_each_free_mem_range*() Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- kernel/kexec_file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- 2.18.0 diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 370d7eab49fe..2f615a7968dd 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -511,8 +511,11 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, phys_addr_t mstart, mend; struct resource res = { }; + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, MEMBLOCK_NONE, &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the @@ -526,8 +529,8 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, break; } } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { + for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, + &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the * range while in kexec, end points to the last byte From patchwork Fri Sep 7 08:00:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146195 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1456941edb; Fri, 7 Sep 2018 01:00:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaXYbp8lTB1bRRIF6vULZipVIukBNtceKfdwwKEpbfQNEdYSBjHwY6tW1pZiS6ogklXRQyp X-Received: by 2002:a62:3644:: with SMTP id d65-v6mr7068156pfa.133.1536307212928; Fri, 07 Sep 2018 01:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307212; cv=none; d=google.com; s=arc-20160816; b=TgQ/sYqwxBV9Du7Ft1n2IDcrLWbNHI/+WIdwL07L2xgOc95aXOZuw44UhokPG5cnby Aeys5RDbEEO/eMhGB+7rCpjpTj8WyOMRTXAysmOkDLWY3hWzpfmkacDdDro/quXzF6Cf pmzcn+MeJgmea8yXrnQRKFkedDfrN45LJJBJwz8l0kXJYYAOGVLMwRcBmd2NCnTn0nF3 rM5c4VpWe6VJXjgMA429CHzw2Z2U0oVuwI6oN6gY1XsEGJkRYFWoIqXa3Py0MLJW4PuQ 9hbg118X1UKwviWMAORem6rpqCK1X+dL5J7iuVyyvz7YSm+9u5BTXy2nTHF/GqpMgikv MNLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=qys+w+KuRNMCFxzjw+1VloWOF/kuhazsT8XZwPi30r4=; b=YWH8ZFVKjsPs8RWC6ZeHnNPY99WO3243E297Gtrz5ZUV0pSzsElq4Fynhm2E5IoLX2 5a2M6Xj54ONzz9ms10nSJXnQN+7lIwR7phhiS5bEenOuaizPEV0fkcUVflSfy3lAO/GN ds4TNkaXx/NuFwqgpKmJETef5tP+4kjOw2Q1jG/JFOuO9TnhvGRbt1CnAnHeLHJ+xKPt LrTd3biLHuzvyVZ9PX9ES5R9QqXItomtBc57G8ehc2IDVBMX9ql4nMN2DDM3tabU3fCn goKe2NTD+28D/bmXtuEwRQ+lMy5ArHsNDwooXqP45FNakxRJZGh5MUctHFe0NVAZ/M5e XaOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="c4/XB92k"; 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 w126-v6si7644617pfb.232.2018.09.07.01.00.12; Fri, 07 Sep 2018 01:00:12 -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="c4/XB92k"; 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 S1728032AbeIGMjy (ORCPT + 32 others); Fri, 7 Sep 2018 08:39:54 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40996 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727806AbeIGMjx (ORCPT ); Fri, 7 Sep 2018 08:39:53 -0400 Received: by mail-pg1-f194.google.com with SMTP id s15-v6so6599269pgv.8 for ; Fri, 07 Sep 2018 01:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=qys+w+KuRNMCFxzjw+1VloWOF/kuhazsT8XZwPi30r4=; b=c4/XB92kJZtTwM5QcIUvrwIc4hwABVpAL6FxknVxyVOPo1m7DFgHA45DOwP7MNdC4f 4++H0GZ8HMGKt/vb64/ye7yqQqgd4CiWLEzoPnE/dykm8dKrH7LJ5wHQ1cvvT6wKZ3pT DgW5JTw45FW5Ko3+dw+4v4HwWeRsrzB67UgfI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qys+w+KuRNMCFxzjw+1VloWOF/kuhazsT8XZwPi30r4=; b=hXF4S7g7G1MtB9SadH9D0z+BhD5Tkw0nUKBKLK2jb3eSpptMx7wlE96sbcN6luaygI a76xi09lx3J23SsAQoeZPdPKdF2W88YPwNS4QLDMELF/H1cKzHAlrL3CcwyjOMjPxryA tcgUT1uOzlkqZl6e06ApBB60mnke2pbeWcy5o3emQ/x5RrHdGO+u7z/RY9kTY4G4LYVL ULVYkFW8wsNHJtyC70lDD75I3Mf3uFeJr3JxSuKoQmg99SqazUvs6/BOegO3UZFshHxV Ll+m0W4FK5Jg5wqRnYTf5LYzij0ZuoYmAW4lMTbrEzI9DpjHPMLFQ7NvDmlURnlal0Xu 5Z/A== X-Gm-Message-State: APzg51Di/T2pwWEd/MUdtw2xqWHoXZN9C6RVdYoIEJEqRYsSrLV+7wqO w5YHjlCs9JDrn/Qz7L4VHpQQGQ== X-Received: by 2002:a63:2d05:: with SMTP id t5-v6mr6916294pgt.403.1536307209430; Fri, 07 Sep 2018 01:00:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y7-v6sm8794078pge.8.2018.09.07.01.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:08 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 , Rob Herring , Frank Rowand Subject: [PATCH v14 06/16] of/fdt: add helper functions for handling properties Date: Fri, 7 Sep 2018 17:00:30 +0900 Message-Id: <20180907080040.4967-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These functions will be used later to handle kexec-specific properties in arm64's kexec_file implementation. Signed-off-by: AKASHI Takahiro Cc: Rob Herring Cc: Frank Rowand --- drivers/of/fdt.c | 62 ++++++++++++++++++++++++++++++++++++++++-- include/linux/of_fdt.h | 10 +++++-- 2 files changed, 68 insertions(+), 4 deletions(-) -- 2.18.0 diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 800ad252cf9c..dc960cea1355 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -25,6 +25,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -537,8 +538,8 @@ void *of_fdt_unflatten_tree(const unsigned long *blob, EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); /* Everything below here references initial_boot_params directly. */ -int __initdata dt_root_addr_cells; -int __initdata dt_root_size_cells; +int dt_root_addr_cells; +int dt_root_size_cells; void *initial_boot_params; @@ -1323,3 +1324,60 @@ late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ + +bool of_fdt_cells_size_fitted(u64 base, u64 size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((dt_root_addr_cells == 1) && (base > U32_MAX)) + return false; + + if ((dt_root_size_cells == 1) && (size > U32_MAX)) + return false; + + return true; +} + +size_t of_fdt_reg_cells_size(void) +{ + return (dt_root_addr_cells + dt_root_size_cells) * sizeof(u32); +} + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + __be32 val32; + + while (cells) { + val32 = cpu_to_fdt32((val64 >> (32 * (--cells))) & U32_MAX); + memcpy(buf, &val32, sizeof(val32)); + buf += sizeof(val32); + } +} + +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size) +{ + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + buf_size = of_fdt_reg_cells_size(); + prop = buf; + + fill_property(prop, addr, dt_root_addr_cells); + prop += dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, dt_root_size_cells); + + return fdt_setprop(fdt, nodeoffset, name, buf, buf_size); +} diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index b9cd9ebdf9b9..9615d6142578 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -37,8 +37,8 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node **mynodes); /* TBD: Temporary export of fdt globals - remove when code fully merged */ -extern int __initdata dt_root_addr_cells; -extern int __initdata dt_root_size_cells; +extern int dt_root_addr_cells; +extern int dt_root_size_cells; extern void *initial_boot_params; extern char __dtb_start[]; @@ -108,5 +108,11 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +bool of_fdt_cells_size_fitted(u64 base, u64 size); +size_t of_fdt_reg_cells_size(void); +int fdt_prop_len(const char *prop_name, int len); +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size); + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_OF_FDT_H */ From patchwork Fri Sep 7 08:00:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146196 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1457198edb; Fri, 7 Sep 2018 01:00:28 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb55aff9dupZbQ0EPi1nZsa3ad1xbPkv86Eyp03zju8xQl5HB4EsKmKPtVYQa51P5dUHOeL X-Received: by 2002:a65:5a81:: with SMTP id c1-v6mr6922379pgt.120.1536307228207; Fri, 07 Sep 2018 01:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307228; cv=none; d=google.com; s=arc-20160816; b=p/Vzx03QsNWjz1nh8QpfXcDp87N+aKLY2hJcs4M595j6fhant+RiUo0rwseIcoRN8U fh0ypG991JzRAJDm6UyNlUmiRIfXUfijLhGTwRqoigezyfEkqcqMMzAQeWpnGIaNxeV9 V9A8FKD6MC0lZB7GHEbBKgxORhVGFIdOndrGlFliSQptTUKl6ag9ihkkR6QVFsB/rV5S e8QFpKbV2QyDyLm4Gew7/YSmNaYgZiKkTeR4xG4wEVVIEKQ3TYI3zAtIY9AKX2BBTlcx EAZmN6DaIY1l76lTbiPo1RPrvuRlANXr1bashz9/VsMMYIqle3uPK5wg+wYJN5JzBY6I Q1Ww== 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; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=qzNnNpbEGphP+10cm44intzwTfbwWLB4CNPEIzr5qUNMY/UbmTk2slIbWQRJ2kXI28 kySXQj3Ng6JopWdr84ztkWzGOtddybSVf5rqqAKhHzwsNA5DDBTHsasSFMsumuE9rGZm 8wsfG1QbMo7weSPnMaaVqHfqctOfLlAMLHqm9NiKfobzGCS7k8GCUf7jxy+FSSmRzUVz ZUbaF2usLvNzgSiQ3L0vW7VnKpfJ06UTJlW4J+rAAd08kSMluHs41bON3jlwBWIiiKr/ i9Uu+skKS69gVERnxkq6CkN6MwrTNKtoxG763BRQXd/VbUmXG3HsKHIhPD0p/7YAZNM7 Txsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Opb8rBTo; 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 w126-v6si7644617pfb.232.2018.09.07.01.00.27; Fri, 07 Sep 2018 01:00:28 -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=Opb8rBTo; 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 S1728074AbeIGMkJ (ORCPT + 32 others); Fri, 7 Sep 2018 08:40:09 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33417 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727366AbeIGMkJ (ORCPT ); Fri, 7 Sep 2018 08:40:09 -0400 Received: by mail-pf1-f195.google.com with SMTP id d4-v6so6644099pfn.0 for ; Fri, 07 Sep 2018 01:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=Opb8rBToQcMZtyPYTVhVnP0kWL6jOjIeziL6TJJFv1WBRD57nZtKirw3Gv+BigdMUA IfnfHFH2jGHiprpQONf+LFBgWyM0iAdDGxdcgKTFHBWR1yJofCRZVngza0NB4IdIuVsN YatTiRLRgRL3dzahQVtG+E4EKQTPVuN5XgPMM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=IwtKhY+kmP0EjiBvhNn/8VhOxSmyvkD/It54fUfME6SsSACyGYb9ItJ3FrjGAZT4YO 35EbHMFtmTHOiAqFPTS7Ckaom18qgB//xPnaO64OG86g7Jo/67edD3x39U8q5pAo8/vm 5/ZyvLUZUP1W7AAozkAxRx911JN44I/Rvhr/viI1XNbUBDNcTLqFE9YgUxCa/qwMJVFh 82XE/yKNOtX0PRs/hjkeWEoFKCt0whO4yfehW8Ub6XjsHYy5DiGxF9W72YN79jaMerGO 1D7nH9p/ic/3Kfb/fcUST7DKmPY6TYJbjTnoCGt6C/lSSKHIKEj+e3UNxE5ckHQlp1i1 Y5bA== X-Gm-Message-State: APzg51CQ7B8KsvdH7NGo3vVprae7JatfcuqlviOv+7EGBPxi+eQar3Pe nMrffQG8+4isHmgEikejf7Y94w== X-Received: by 2002:a62:ed5:: with SMTP id 82-v6mr7109449pfo.198.1536307224906; Fri, 07 Sep 2018 01:00:24 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o10-v6sm7788864pgp.70.2018.09.07.01.00.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:24 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 07/16] arm64: add image head flag definitions Date: Fri, 7 Sep 2018 17:00:31 +0900 Message-Id: <20180907080040.4967-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Those image head's flags will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Acked-by: James Morse --- arch/arm64/include/asm/boot.h | 15 +++++++++++++++ arch/arm64/kernel/head.S | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) -- 2.18.0 diff --git a/arch/arm64/include/asm/boot.h b/arch/arm64/include/asm/boot.h index 355e552a9175..0bab7eed3012 100644 --- a/arch/arm64/include/asm/boot.h +++ b/arch/arm64/include/asm/boot.h @@ -5,6 +5,21 @@ #include +#define ARM64_MAGIC "ARM\x64" + +#define HEAD_FLAG_BE_SHIFT 0 +#define HEAD_FLAG_PAGE_SIZE_SHIFT 1 +#define HEAD_FLAG_BE_MASK 0x1 +#define HEAD_FLAG_PAGE_SIZE_MASK 0x3 + +#define HEAD_FLAG_BE 1 +#define HEAD_FLAG_PAGE_SIZE_4K 1 +#define HEAD_FLAG_PAGE_SIZE_16K 2 +#define HEAD_FLAG_PAGE_SIZE_64K 3 + +#define head_flag_field(flags, field) \ + (((flags) >> field##_SHIFT) & field##_MASK) + /* * arm64 requires the DTB to be 8 byte aligned and * not exceed 2MB in size. diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index b0853069702f..8cbac6232ed1 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -91,7 +91,7 @@ _head: .quad 0 // reserved .quad 0 // reserved .quad 0 // reserved - .ascii "ARM\x64" // Magic number + .ascii ARM64_MAGIC // Magic number #ifdef CONFIG_EFI .long pe_header - _head // Offset to the PE header. From patchwork Fri Sep 7 08:00:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146197 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1457359edb; Fri, 7 Sep 2018 01:00:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYgJQveOkWXW5ltxqzIOxmNMkiC/LH/7qBdwZgN6Hvriq7hRS5QSxqW7n4wFkEs4iaXwq0D X-Received: by 2002:a63:9a42:: with SMTP id e2-v6mr7059307pgo.263.1536307237322; Fri, 07 Sep 2018 01:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307237; cv=none; d=google.com; s=arc-20160816; b=YowbU3YEaMcwK3oxSCs8exAfyY/BC5JU/XirkI9wLWUMhGmdYMwoy2v5znV+A+bhNu HvUVzVC4hs7rUvwVL3iU5WZyndg48f1VI5lRM/p3flulTaOKrVoeaA2XhH12dr0xBGQ2 F1rE3xwAaHP+q7A8tAk2xQLAKZGEH+ws3ufFP5d8IPuF3vn8FzJHA39DfB0NYnLjP+EE vmm+9tjN0Wpdpjfc17nSbByhhuwWUHhwFfSWTC6h6N1zeXbhGxugCGiN5skbgxqCFeB/ ZQUX3A+Q/rRLUX4jsYWRdlpqS/HH3jW1SNILbNtx4XTx14GRfUntoxOiMZjyztDfRlgv BjZA== 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; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=o8bqA1ViRC4k9C4KO8/UWL3j1jXCuOkc9VJcA6QKRKsJKeB2dGf4QxdgZEc++8aD+Y PU4Tsy2dQfmaGLCe4bRFinY0KJmz6U5yhjFm4vf3f6zoKhFERQLISbdxl5J+PY9pqhqg cZNiTEyYgpJr1ELaQXy/q0zAnydhQcCk6u/Ge9OFbvv+JoLj8AJDGk+OSavu02Nic2rK lsKwwdSrH/6+tyiQYWIuHkDz6a0RIh4HY3wsZ1WiPV+Wfs1DhXnuma7tj/S3H0iIGBIv KcvbAXjQ3gnrPymeyRuvAiiILBib7AGsIhe9yUXGuRX4HSvVEf5GvNf8bWzegPE3QExw yl5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TmH1QzWE; 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 t1-v6si7459896pgg.643.2018.09.07.01.00.37; Fri, 07 Sep 2018 01:00: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=TmH1QzWE; 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 S1728087AbeIGMkT (ORCPT + 32 others); Fri, 7 Sep 2018 08:40:19 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45813 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727366AbeIGMkT (ORCPT ); Fri, 7 Sep 2018 08:40:19 -0400 Received: by mail-pl1-f194.google.com with SMTP id j8-v6so6222688pll.12 for ; Fri, 07 Sep 2018 01:00:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=TmH1QzWEdjIScRitGPZDxo0kRunrfKh346dMTCHgL4WemhLrgJXrLlzBjN+nCXAuWy gCDKxLM8kTmf+MYRZA461r8JZjKI8C0b8KAyNi4UI++fnhOpsvPUJRFcCrtn0F4l/PIG ASgLni1wy+APVrPqon048Ll4ug/DU23G3WwCM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=JN6rtj3FOmyBNF4GLpS2/5OGCao9ACmYmvPAZZ2txIZBea+pMq/ydFkF08jiNbT/Kj 8QYejLQigMoln+N0stkUJ9TtkKWwc3wlIXiU8JJADUFlHelDWQSXCP6GS4ok0/Jr22Mn z5t9B/pbRPf7V1BdRq07odOJ1SkEMd3RQY7O9aiRPaKEoLIvK9tNc3OQNwufTc6cDdQl IuoetK2lRlmqCbARrc/7J4VYXrcHV7yQnTCj3e+AEfMjMaWO+qLJDf+6A2ns5oO5m1eb zAvYD3laidsI8VNsbKXW+0ZsyCOib2DxXhSp1udoBrZt9fFSbhJ0tW+NTZVAXGKAFG2X J3VA== X-Gm-Message-State: APzg51Ag9/EswocK/Wq1vWYHXIrzNYJh4hCYJLvSNxdbh0mzfsdVL1/r sWbHo1sDqqcJ7iUhBo137r6/cA== X-Received: by 2002:a17:902:20c6:: with SMTP id v6-v6mr6826590plg.228.1536307234715; Fri, 07 Sep 2018 01:00:34 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d19-v6sm12812464pgi.50.2018.09.07.01.00.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:34 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Fri, 7 Sep 2018 17:00:32 +0900 Message-Id: <20180907080040.4967-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Those helper functions for MMFR0 register will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/cpufeature.h | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) -- 2.18.0 diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 1717ba1db35d..cd90b5252d6d 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -486,11 +486,59 @@ static inline bool system_supports_32bit_el0(void) return cpus_have_const_cap(ARM64_HAS_32BIT_EL0); } +static inline bool system_supports_4kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN4_SHIFT); + + return val == ID_AA64MMFR0_TGRAN4_SUPPORTED; +} + +static inline bool system_supports_64kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN64_SHIFT); + + return val == ID_AA64MMFR0_TGRAN64_SUPPORTED; +} + +static inline bool system_supports_16kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN16_SHIFT); + + return val == ID_AA64MMFR0_TGRAN16_SUPPORTED; +} + static inline bool system_supports_mixed_endian_el0(void) { return id_aa64mmfr0_mixed_endian_el0(read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1)); } +static inline bool system_supports_mixed_endian(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_BIGENDEL_SHIFT); + + return val == 0x1; +} + static inline bool system_supports_fpsimd(void) { return !cpus_have_const_cap(ARM64_HAS_NO_FPSIMD); From patchwork Fri Sep 7 08:00:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146198 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1457508edb; Fri, 7 Sep 2018 01:00:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZL9ie+VXsV8N80motI9t1AvB73mqHyxxbAssuuEDiFnc2k7YY/r2mfIbTdIeUzZ9gQLy+4 X-Received: by 2002:a17:902:a983:: with SMTP id bh3-v6mr6561811plb.245.1536307246796; Fri, 07 Sep 2018 01:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307246; cv=none; d=google.com; s=arc-20160816; b=ux+SQvhCGeykNiepgAERvTKRcMiNBeeahgUsrLW7m6iqKnW/JzaeuIMGc/gWhNaFCX Ab/FheGSSQQtfYYva68b+P1iEqh4itb4qWiONoW1uNLXoyl6kXzWf9AcrpwDOP53i/PL ncSpkvYMmCNNDNah5R7DEglVGqul2bY2jTp679yeIl73lGnTS7lfgUQmARytPGKgo4Ny Va+5rb1GS51Y8JqlkeA8XWeFMPd+cp9UQn+XqcibDXLFI9UJFnx82Lq6Wr7KWokaJxSN BJNiN9JhBbwP7P7j2F7j7dMPrxwXCxOscpQLEtX8R1h+mJwhKWPAESGAAAb6qwt0JKMC JhtQ== 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; bh=Wek53x727l+CC28Me3kZmv40INMNgym0MEOVv8aRsME=; b=1HS87H+MRi+drvffA5V16wOnOfr/LkGu+uMo4VB6jQdn4sRFE6DKKdxIN7GuVQ8W3y cotXp1ZCLnE4CYuV2+SvkEK0zhBKTjoHH+gLOkh4J5Wn+c4xSp97GcWq7oZtw9KvzxLB glUNKDkWgcIZAFPH4/sTcxTxP4BB6Lxq9YPi7C0CM52TcaHMQ+ZGpLWHLes6pojUgf8N Zg0ZQicFtATOwmBhKUwQ6zgVpCuw6ikPnbDLH/9R5vgSniq8n6tHtEPKJ22oB8+E5h9E WL29xUKyg11j+3/ud1u1VIJ2QG9Vir+dc7xTB1yjHQfExjWd/gpn1zVXQA6znx40WN5e +K3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aMLoGtcK; 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 t1-v6si7459896pgg.643.2018.09.07.01.00.46; Fri, 07 Sep 2018 01:00:46 -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=aMLoGtcK; 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 S1728102AbeIGMk2 (ORCPT + 32 others); Fri, 7 Sep 2018 08:40:28 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43742 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728055AbeIGMk2 (ORCPT ); Fri, 7 Sep 2018 08:40:28 -0400 Received: by mail-pl1-f193.google.com with SMTP id h3-v6so2872425plh.10 for ; Fri, 07 Sep 2018 01:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Wek53x727l+CC28Me3kZmv40INMNgym0MEOVv8aRsME=; b=aMLoGtcKbZtYcDTYknTxqNRmjzsz5TmpU8UWKlGEgq3ouS/mEmCdeUyli8+9dThfXm 331KELwilkTkuU7ES4+trm/OnppENYt26MmHYfI5U7PogvC7XuwianlCKX3lWU4pV42N hI0QmcAvNmIyFcxP0XBOj904YNTV9anFCZLtg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Wek53x727l+CC28Me3kZmv40INMNgym0MEOVv8aRsME=; b=CQNHCcr8awDaulXZ8+NDmdNGP7nTbJw4Nl7y2mx8aLW3bYHFxTg8OimSvhrCqPgriV YjvwQeBJ2hAZYfLuxmj8jMddQTnyd92c6QSkqrjfiQgevCraAveRIo4NNYDesB0Not25 tMT1FzeZJU/dl5Mjx7DGDwsk5rHRdx6qaNyNOw6KYKzD8DduThUzAX2PcCwFT/YDwPWp rBrgxIKaUOkgal0K3P5bAogjOh2vi8n41WKf5Hay7PqXBmH7q2pxGVnizdF4ki5dehEZ 5tMD3/jsA3jNnbWNoknl9mWM2YjsD49B0uhflOr95OhjLZt5Z7b/WhrNDh4gYjKHFl2A IByA== X-Gm-Message-State: APzg51CAFF2g8ISpKtFK7Zde00IvdhVUpapq4YygdnMA0XaVYCmcDENH QvCjGiqmI0fgZewX93xRwZL74w== X-Received: by 2002:a17:902:464:: with SMTP id 91-v6mr6757431ple.125.1536307243989; Fri, 07 Sep 2018 01:00:43 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f6-v6sm9369907pgf.52.2018.09.07.01.00.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:43 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 09/16] arm64: enable KEXEC_FILE config Date: Fri, 7 Sep 2018 17:00:33 +0900 Message-Id: <20180907080040.4967-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> 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 Acked-by: James Morse --- arch/arm64/Kconfig | 9 +++++++++ arch/arm64/kernel/Makefile | 3 ++- arch/arm64/kernel/machine_kexec_file.c | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/machine_kexec_file.c -- 2.18.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1b1a0e95c751..5eb18d0cb513 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -843,6 +843,15 @@ config KEXEC but it is independent of the system firmware. And like a reboot you can start any kernel with it, not just Linux. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + help + This is new version of kexec system call. This system call is + file based and takes file descriptors as system call argument + for kernel and initramfs as opposed to list of segments as + accepted by previous system call. + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 95ac7374d723..8f1326b2d327 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -49,8 +49,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..c38a8048ed00 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; From patchwork Fri Sep 7 08:00:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146199 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1457673edb; Fri, 7 Sep 2018 01:00:56 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYTq39+ew8w1cUYjLTzPmiLNb1CnWo+iuFBjAB1NybujWgcScAdYWkgzJ4a28XqL+eSO/9t X-Received: by 2002:a62:fcd2:: with SMTP id e201-v6mr7205326pfh.101.1536307256523; Fri, 07 Sep 2018 01:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307256; cv=none; d=google.com; s=arc-20160816; b=Am1btW87LQzb4hz1HXz22LowQjwSEsC/wAXUJ/PhJ4DEimUzTiBzh90TFre0aD5/vF tGjzeJWJ8+ExPwDa8NcWJ4cygj5KdivC75SJ23niEhc5rKFY35yLRjlgdWWfggYe3rmb bEmUqmhkrwBLDnKQ4XWDM7RRaknHgEB3NLFhZ/SVTTJjqLDaXNmngnLLcaoqM/YQ1gZX MjxG/ebxAKjh3pSLM5HEF1cowqtBvUeHrnkUYRK3FOcDu+q7WImxnjw9sVbwRSlreCAY nFu/zR5BM4vL4VTnGgIrou+kbnLxpJU8AqIARa2BByKj+zAyQc/P2SgbYY99Wta6mPyH cBLg== 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; bh=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=K15/fgiIQblQt7ox3KUFdAc7Jg6gnLmH6vqFoiLgmn/lVyWLtr2pSaCbfsjfqkmr0Y Hihh0bV9G1EfFptz3WU97m1HigTCkT3P8peuCbf5RXZXPETxbavqIx9Rt630h7ZfBaVo Sliqk1hFY9wZhLvBgZhZn4ysB4ocoNNYCH+hbBNmBSvyDCkzKlOiXLYBzySyjqP/MhSa xMGvr1BCOpbhgaVzyXcY209srX7E3X89KdU2e/dT7N3H5TlfYtRC/xw+BbMeA3gPm+88 8H9fDFfBDcxnuEPD6FIzgDndpPa1GPxItM0L5XMWi/rjJLlSCTBqnVIkkP9lfxVNiQhN dZag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MZ9A3QxJ; 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 t23-v6si8069218pgk.26.2018.09.07.01.00.56; Fri, 07 Sep 2018 01:00:56 -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=MZ9A3QxJ; 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 S1728132AbeIGMki (ORCPT + 32 others); Fri, 7 Sep 2018 08:40:38 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38602 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbeIGMki (ORCPT ); Fri, 7 Sep 2018 08:40:38 -0400 Received: by mail-pl1-f195.google.com with SMTP id u11-v6so6231252plq.5 for ; Fri, 07 Sep 2018 01:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=MZ9A3QxJ7yRFgCIEoDFMglvR9MFB25h+UXHZBcN7/UOYpmmUXgi1mSCgTP+t/wweU0 zwdH74SMalwuKNMY0AKwCfQ5f1pJS+9JZj7BJZoARJLLUyk5aTxJjMD6xisomeA4BNng aKJBLMbfPRiLXNAnDCTTDLTUryjVXLq/w4MEI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=aanWjAZ4+n5ik5EJ3RduIz5j7kAES6xHDElXHexhqIA6Is+R+03C9ju4nuSbfe+FcN Gwjdhaejg+nHZZAr9R0mXt3v9CrMlH+OdChaTmN36nQhhD23eKABi2XfYqR2u5PLJs0M DGWv31jaIfqO8780UHvDQ7VXZmJCNo5YPLDnFNqPvAe1DN4wo985PddXczVemW4ak/LC QcZ3qWkLcyqrcWZr14IcICf+DB2Am6suBdf4KALhrRG7hIgW9+ZuBag0/CP3R3PBgNwe EA5nCI2Hb8ZDmP4/5EkAfNg88vJN+129Jc504SpghqcW6chRsfv3G9vfVHcip4ZXg6wV LlGQ== X-Gm-Message-State: APzg51DMZsIimBLmawZrz0Yi0mdLXRKyVQORx8NhR5IOySZDXE1CeD0s 4axOS3yjDuT76A3bKuSOU8imyw== X-Received: by 2002:a17:902:3c5:: with SMTP id d63-v6mr6654075pld.145.1536307253444; Fri, 07 Sep 2018 01:00:53 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d12-v6sm10819689pfk.69.2018.09.07.01.00.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:00:52 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 10/16] arm64: kexec_file: load initrd and device-tree Date: Fri, 7 Sep 2018 17:00:34 +0900 Message-Id: <20180907080040.4967-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> 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 the original boot loader is reused. arch_kimage_kernel_post_load_cleanup() is responsible for freeing arm64- specific data allocated in load_other_segments(). Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 17 +++ arch/arm64/kernel/machine_kexec_file.c | 188 +++++++++++++++++++++++++ 2 files changed, 205 insertions(+) -- 2.18.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..157b2897d911 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,23 @@ static inline void crash_prepare_suspend(void) {} static inline void crash_post_resume(void) {} #endif +#ifdef CONFIG_KEXEC_FILE +#define ARCH_HAS_KIMAGE_ARCH + +struct kimage_arch { + void *dtb; + unsigned long dtb_mem; +}; + +struct kimage; + +extern int arch_kimage_file_post_load_cleanup(struct kimage *image); +extern int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index c38a8048ed00..f53f14bd1700 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,200 @@ * Copyright (C) 2018 Linaro Limited * Author: AKASHI Takahiro * + * Most code is derived from arm64 port of kexec-tools */ #define pr_fmt(fmt) "kexec_file: " fmt +#include +#include #include +#include +#include +#include +#include +#include + +/* relevant device tree properties */ +#define FDT_PSTR_INITRD_STA "linux,initrd-start" +#define FDT_PSTR_INITRD_END "linux,initrd-end" +#define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { NULL }; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb); + image->arch.dtb = NULL; + + return kexec_image_post_load_cleanup_default(image); +} + +static int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + void **dtb_buf, unsigned long *dtb_buf_len) +{ + void *buf = NULL; + size_t buf_size; + int nodeoffset; + int ret; + + /* duplicate dt blob */ + buf_size = fdt_totalsize(initial_boot_params); + + if (initrd_load_addr) { + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len(FDT_PSTR_INITRD_STA, sizeof(u64)); + buf_size += fdt_prop_len(FDT_PSTR_INITRD_END, sizeof(u64)); + } + + if (cmdline) + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len(FDT_PSTR_BOOTARGS, cmdline_len); + + buf = vmalloc(buf_size); + if (!buf) { + ret = -ENOMEM; + goto out_err; + } + + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + nodeoffset = fdt_path_offset(buf, "/chosen"); + if (nodeoffset < 0) { + ret = -EINVAL; + goto out_err; + } + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop_string(buf, nodeoffset, FDT_PSTR_BOOTARGS, + cmdline); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_BOOTARGS); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_INITRD_STA, + initrd_load_addr); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_INITRD_END, + initrd_load_addr + initrd_len); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_INITRD_STA); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_delprop(buf, nodeoffset, FDT_PSTR_INITRD_END); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* trim a buffer */ + fdt_pack(buf); + *dtb_buf = buf; + *dtb_buf_len = fdt_totalsize(buf); + + return 0; + +out_err: + vfree(buf); + return ret; +} + +int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + void *dtb = NULL; + unsigned long initrd_load_addr = 0, dtb_len; + int ret = 0; + + kbuf.image = image; + /* not allocate anything below the kernel */ + kbuf.buf_min = kernel_load_addr + kernel_size; + + /* load initrd */ + if (initrd) { + kbuf.buffer = initrd; + kbuf.bufsz = initrd_len; + kbuf.mem = 0; + kbuf.memsz = initrd_len; + kbuf.buf_align = 0; + /* within 1GB-aligned window of up to 32GB in size */ + kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + + (unsigned long)SZ_1G * 32; + kbuf.top_down = false; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + initrd_load_addr = kbuf.mem; + + pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + initrd_load_addr, initrd_len, initrd_len); + } + + /* load dtb blob */ + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, cmdline_len, &dtb, &dtb_len); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + kbuf.buffer = dtb; + kbuf.bufsz = dtb_len; + kbuf.mem = 0; + kbuf.memsz = dtb_len; + /* not across 2MB boundary */ + kbuf.buf_align = SZ_2M; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + image->arch.dtb = dtb; + image->arch.dtb_mem = kbuf.mem; + + pr_debug("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kbuf.mem, dtb_len, dtb_len); + + return 0; + +out_err: + vfree(dtb); + return ret; +} From patchwork Fri Sep 7 08:00:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146200 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1457891edb; Fri, 7 Sep 2018 01:01:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZHtSHiEJ/rg7EngJi27OJ1bbIhz9QsnefJmypQghzAD3xCA6TK3ZzDA5mS6IfLLBisxw2j X-Received: by 2002:a63:d806:: with SMTP id b6-v6mr6792787pgh.347.1536307271768; Fri, 07 Sep 2018 01:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307271; cv=none; d=google.com; s=arc-20160816; b=Tc7fd0FZhmHdsLPOyahtqOtNWyre8V1OR6DGCpF4McY+xtODygok+EDLYTh8cUoiyg hyHMgjxSYW7wjz7BpYM4ig9sMn08YaTYD+s9nSNvJAiKYoJ/fnMpmFK01QxS+F3CgmSC 02WLvP+YYbyZinLYggJOlZla6qn0ZBkuKESC4V/JHlyBkPn6Pl5LcYXHM7t2k4uXN9tw KBmwTjToRBQz//BpSh3cmyL/SDCja8a7KEkIsqQGknoAw+y0/e3XjtSmN8CyqjXWh+XM iMVUFWVbUDN10HPA6awrtsbJlgtVPT3QO7JvxFEMX9uQq7x/SHT0f5indq5cgawS58lE zLnw== 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; bh=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=iyvkFwM9U6/n1omflYeh8iK6zdnxTM2gXsZRtcmLf24ELAbtMTKXW8Ji5sxFIHPCex X1+qLa4cn3FCYuZHM56aFppImTi0xHIoqcklmzFYKnVxH8NLkQRXRfQG/T4gaL7nKHx1 7LcJ5aaBcJdRveYu1eYGbTTpyDOl7ybK3MzDDFj/VhNJnZ/rk3L9xHkpulJ4CnV7F8hg x2ee/ESVPBg6cUMENaysW4r+XZj8xPfbK7cy/GJ7j1uD2VNrfoH3zjtC2qHeWDKHtdib GSzfpKe71WY1PBjyh/khgi5VB0PJx3YwsI33vXbJYcWCXLmTlh6gbW5jV67xQmKMgvCx oiiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cCvWfWiP; 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 w11-v6si7937773pgm.616.2018.09.07.01.01.11; Fri, 07 Sep 2018 01:01:11 -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=cCvWfWiP; 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 S1728164AbeIGMkx (ORCPT + 32 others); Fri, 7 Sep 2018 08:40:53 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38435 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728002AbeIGMkw (ORCPT ); Fri, 7 Sep 2018 08:40:52 -0400 Received: by mail-pf1-f193.google.com with SMTP id x17-v6so6643475pfh.5 for ; Fri, 07 Sep 2018 01:01:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=cCvWfWiPrepkCS1NeuS+dm7T4KZLOOTVOQ9PbY1I/rAycwyxcyjhvq7fdTPlnql/Uj tYtRa2vSQq3G1DDOWuXI+H92QtlIflCSgQTif37ykruNXrmX9DGKMFQ3s8pGvMgQ5SOI W0SeDvIQNkB05GH/M5apTpH1wacLOPVuVGYFQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=uGBKJtwB4Q49DAgoth4cRK7a4/0UEEU3P7qvJZmfqIlKKtUAYl3nXAYjbjgFnCCMvC gx6Nw4ayVSBHY7UlfKRT6JB7BOKpEuZ8ChV4HXpoj0imw7S0PFmZjK3jdmBHA2op2u/u orGKj0bLCaJPc9WYIIGycbIcuGpZ0R5PxLn5e06qxPvlnYWJBwIif7XGdvzcWoQgIaNT m8b46wl4k0/MIBRKVl562urG1cwAnTVIsOyPqeu0uY/BbHz79qagNb2Ig00UTDdmCc7l s7YuLpPFprH18jes/x4BHcQUFhRoS5xgifV18u1zcYoJoRizttzQ8uXJYgqYMedv2/c4 tPVg== X-Gm-Message-State: APzg51AdI20jqWlSEI65bn8VvWxS0UbQkij0UjfEYBVTVhtXU5Te7FQF Xjib/x/bfgGi2LR/KC/GPI8QVw== X-Received: by 2002:a63:d343:: with SMTP id u3-v6mr6922649pgi.420.1536307267025; Fri, 07 Sep 2018 01:01:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r25-v6sm8762276pgm.59.2018.09.07.01.01.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:06 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Fri, 7 Sep 2018 17:00:35 +0900 Message-Id: <20180907080040.4967-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> 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 Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 28 +++++++ arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/kexec_image.c | 108 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 1 + 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/kexec_image.c -- 2.18.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 157b2897d911..5e673481b3a3 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -101,6 +101,34 @@ struct kimage_arch { unsigned long dtb_mem; }; +/** + * struct arm64_image_header - arm64 kernel image header + * See Documentation/arm64/booting.txt for details + * + * @mz_magic: DOS header magic number ('MZ', optional) + * @code1: Instruction (branch to stext) + * @text_offset: Image load offset + * @image_size: Effective image size + * @flags: Bit-field flags + * @reserved: Reserved + * @magic: Magic number + * @pe_header: Offset to PE COFF header (optional) + **/ + +struct arm64_image_header { + __le16 mz_magic; /* also code0 */ + __le16 pad; + __le32 code1; + __le64 text_offset; + __le64 image_size; + __le64 flags; + __le64 reserved[3]; + __le32 magic; + __le32 pe_header; +}; + +extern const struct kexec_file_ops kexec_image_ops; + struct kimage; extern int arch_kimage_file_post_load_cleanup(struct kimage *image); diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 8f1326b2d327..8cd514855eec 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -51,7 +51,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..d64f5e9f9d22 --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kexec image loader + + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + */ + +#define pr_fmt(fmt) "kexec_file(Image): " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int image_probe(const char *kernel_buf, unsigned long kernel_len) +{ + const struct arm64_image_header *h; + + h = (const struct arm64_image_header *)(kernel_buf); + + if (!h || (kernel_len < sizeof(*h)) || + memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) + return -EINVAL; + + return 0; +} + +static void *image_load(struct kimage *image, + char *kernel, unsigned long kernel_len, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct arm64_image_header *h; + u64 flags, value; + struct kexec_buf kbuf; + unsigned long text_offset; + struct kexec_segment *kernel_segment; + int ret; + + /* Don't support old kernel */ + h = (struct arm64_image_header *)kernel; + if (!h->text_offset) + return ERR_PTR(-EINVAL); + + /* Check cpu features */ + flags = le64_to_cpu(h->flags); + value = head_flag_field(flags, HEAD_FLAG_BE); + if (((value == HEAD_FLAG_BE) && !IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) || + ((value != HEAD_FLAG_BE) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))) + if (!system_supports_mixed_endian()) + return ERR_PTR(-EINVAL); + + value = head_flag_field(flags, HEAD_FLAG_PAGE_SIZE); + if (((value == HEAD_FLAG_PAGE_SIZE_4K) && + !system_supports_4kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_64K) && + !system_supports_64kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_16K) && + !system_supports_16kb_granule())) + return ERR_PTR(-EINVAL); + + /* Load the kernel */ + kbuf.image = image; + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = false; + + kbuf.buffer = kernel; + kbuf.bufsz = kernel_len; + kbuf.mem = 0; + kbuf.memsz = le64_to_cpu(h->image_size); + text_offset = le64_to_cpu(h->text_offset); + kbuf.buf_align = MIN_KIMG_ALIGN; + + /* Adjust kernel segment with TEXT_OFFSET */ + kbuf.memsz += text_offset; + + ret = kexec_add_buffer(&kbuf); + if (ret) + return ERR_PTR(ret); + + kernel_segment = &image->segment[image->nr_segments - 1]; + kernel_segment->mem += text_offset; + kernel_segment->memsz -= text_offset; + image->start = kernel_segment->mem; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kernel_segment->mem, kbuf.bufsz, + kernel_segment->memsz); + + /* Load additional data */ + ret = load_other_segments(image, + kernel_segment->mem, kernel_segment->memsz, + initrd, initrd_len, cmdline, cmdline_len); + + return ERR_PTR(ret); +} + +const struct kexec_file_ops kexec_image_ops = { + .probe = image_probe, + .load = image_load, +}; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index f53f14bd1700..05fb2d4e6fef 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -25,6 +25,7 @@ #define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Fri Sep 7 08:00:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146201 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1458019edb; Fri, 7 Sep 2018 01:01:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZmiNZuMKAXXFty23VNFK5GG/ElCS902E5r4/ZHFApuSEMTtLL20Q2tT/w8c45FIJcZp8yG X-Received: by 2002:a63:447:: with SMTP id 68-v6mr6880042pge.409.1536307280390; Fri, 07 Sep 2018 01:01:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307280; cv=none; d=google.com; s=arc-20160816; b=grPPrDlP3NFeHBwqstpiZOBGP/pAfpDCG1hLERNLIBKDzDf1dXA9uZXnL6GokLkYrw YnIchyUQHXLzyDjEkL+gGercXMVKDPbC+wCeYyOrvjlgeOnDduJHJaWtA4vZWj29sW3R yWR4PcFYmPp4+UcjhpEoJ2mdMWa92oImavxTB5ja2lSYvYl/XPbrpzbaDbkMEsGx+4oY rTslFgM9GcpW4SovDc50CVm8Bc7YP2fjLZqZByPiWsWTN6DGpNRyEXqcAQcD2QSyqkGN Vy5m0oT3EVfteZAVEihXYZw9Pwr8sxYWMpz+it34f605ejlRsq68PccXwWLmknR09REr ZMdg== 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; bh=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=lsJ9aPF7OKZ7nVS5frb/ZY88nJ4KBfqId2igrzlo285lmZkXhHMlk77o0n5b/eIphW TrpifuD0ahowFJSmNlkR3q3NrDkAjjdkx/1Vs3tm1gGzvJ7Wl9+xXS2zhLSQA39WQ8YB 6Kapk1iHH9dmYosPepkghd9h/UlD8HEiLSRcufFdrV20Bli/ORe8zFxXWhWj0QM2mUVt DlexE9CN3PbQhLDpjCii10pWfOiSCw9xv9TLAhtnWh5PzDcHf5wtXfTwe2Nftfcy7vwu 9q84p2OFUC3uuupd1lHwneFEz0qdeM0ZU82Sd2pvoNZc8l/rIKs1Mb9hI6Vr4tclJhz9 zWog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TfbOiWS9; 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 w11-v6si7937773pgm.616.2018.09.07.01.01.20; Fri, 07 Sep 2018 01:01: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=TfbOiWS9; 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 S1728173AbeIGMlC (ORCPT + 32 others); Fri, 7 Sep 2018 08:41:02 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:47058 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbeIGMlC (ORCPT ); Fri, 7 Sep 2018 08:41:02 -0400 Received: by mail-pf1-f196.google.com with SMTP id u24-v6so6617695pfn.13 for ; Fri, 07 Sep 2018 01:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=TfbOiWS9heV3iy9bKjpBx5utWenk+HNyevEckxzOh1Da1c1e6NsmI/2Iv/5VrDEe1+ +Ci63eYbIj4xmAgxJ2/HliOUTtKtoqLHvlz/pnkAEkO5/7WwJpj1MwTmT1Gqw7aZKqbH hMwcKiLnQU311Hir4ZdnMA3tU6k8KIHwEVk7c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=RgPEbOcooFtHhnDF59kUaxN2sWbjxS9H2Y4xQssbPOHyD0j+gqLFqyOJaiYo1UxfW9 FKrFni7tZToEF3xfUnM6hSlySLJ+rmkRLDJH8j4WK6dBi6cF/js621pEJbIZec2943ph SRmK59gRW9DGhmvSmeskIy3YbYBdIzbci71HiYT7Ea2qFjF8Z3hh45hmeOwl/61PduCT RagMSmVZm02FzEaAg53b6F/+FA7LSFq7lOaCY+FwlZjXz5rQcsmt/mA16L7rVmDU2Rg4 h/Wu1QQCTvvEj/sv01/mEIIfFVfUIybb7TM5T1iXrUk6HjnG2N09hymX7CfyCZZyAPcs /umw== X-Gm-Message-State: APzg51AxoR7w5rEdR2h173dsD0fUT+JG7QSwS6jP7Zj2Zhd/MjMDTajE lLDWXQbDnTltORg7nzmjSSjGqw== X-Received: by 2002:a63:f44d:: with SMTP id p13-v6mr7072731pgk.257.1536307276719; Fri, 07 Sep 2018 01:01:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c20-v6sm18010130pfh.143.2018.09.07.01.01.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:15 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 12/16] arm64: kexec_file: add crash dump support Date: Fri, 7 Sep 2018 17:00:36 +0900 Message-Id: <20180907080040.4967-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> 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 respectively a memory range to be used by crash dump kernel and the header's location Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/kexec.h | 4 + arch/arm64/kernel/machine_kexec_file.c | 113 ++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 3 deletions(-) -- 2.18.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 5e673481b3a3..1b2c27026ae0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -99,6 +99,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb; unsigned long dtb_mem; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_mem; + unsigned long elf_headers_sz; }; /** diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 05fb2d4e6fef..ecaecb122cad 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,10 +16,14 @@ #include #include #include +#include #include +#include #include /* relevant device tree properties */ +#define FDT_PSTR_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PSTR_MEM_RANGE "linux,usable-memory-range" #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" @@ -34,6 +38,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb); image->arch.dtb = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return kexec_image_post_load_cleanup_default(image); } @@ -43,12 +51,29 @@ static int setup_dtb(struct kimage *image, void **dtb_buf, unsigned long *dtb_buf_len) { void *buf = NULL; - size_t buf_size; + size_t buf_size, range_size; int nodeoffset; int ret; + /* check ranges against root's #address-cells and #size-cells */ + if (image->type == KEXEC_TYPE_CRASH && + (!of_fdt_cells_size_fitted(image->arch.elf_headers_mem, + image->arch.elf_headers_sz) || + !of_fdt_cells_size_fitted(crashk_res.start, + crashk_res.end - crashk_res.start + 1))) { + pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n"); + ret = -EINVAL; + goto out_err; + } + /* duplicate dt blob */ buf_size = fdt_totalsize(initial_boot_params); + range_size = of_fdt_reg_cells_size(); + + if (image->type == KEXEC_TYPE_CRASH) { + buf_size += fdt_prop_len(FDT_PSTR_KEXEC_ELFHDR, range_size); + buf_size += fdt_prop_len(FDT_PSTR_MEM_RANGE, range_size); + } if (initrd_load_addr) { /* can be redundant, but trimmed at the end */ @@ -78,6 +103,22 @@ static int setup_dtb(struct kimage *image, goto out_err; } + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(buf, nodeoffset, FDT_PSTR_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(buf, nodeoffset, FDT_PSTR_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(buf, nodeoffset, FDT_PSTR_BOOTARGS, @@ -135,6 +176,43 @@ static int setup_dtb(struct kimage *image, return ret; } +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + unsigned int nr_ranges; + int ret; + u64 i; + phys_addr_t start, end; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) + nr_ranges++; + + cmem = kmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL); + if (!cmem) + return -ENOMEM; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) { + cmem->ranges[cmem->nr_ranges].start = start; + cmem->ranges[cmem->nr_ranges].end = end - 1; + cmem->nr_ranges++; + } + + /* Exclude crashkernel region */ + ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + + if (!ret) + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -142,14 +220,43 @@ int load_other_segments(struct kimage *image, char *cmdline, unsigned long cmdline_len) { struct kexec_buf kbuf; - void *dtb = NULL; - unsigned long initrd_load_addr = 0, dtb_len; + void *headers, *dtb = NULL; + unsigned long headers_sz, initrd_load_addr = 0, dtb_len; int ret = 0; kbuf.image = image; /* not allocate anything below the kernel */ kbuf.buf_min = kernel_load_addr + kernel_size; + /* load elf core header */ + if (image->type == KEXEC_TYPE_CRASH) { + ret = prepare_elf_headers(&headers, &headers_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + goto out_err; + } + + kbuf.buffer = headers; + kbuf.bufsz = headers_sz; + kbuf.mem = 0; + kbuf.memsz = headers_sz; + kbuf.buf_align = SZ_64K; /* largest supported page size */ + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(headers); + goto out_err; + } + image->arch.elf_headers = headers; + image->arch.elf_headers_mem = kbuf.mem; + image->arch.elf_headers_sz = headers_sz; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_headers_mem, headers_sz, headers_sz); + } + /* load initrd */ if (initrd) { kbuf.buffer = initrd; From patchwork Fri Sep 7 08:00:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146202 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1458146edb; Fri, 7 Sep 2018 01:01:30 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbXLwRWeCIq4kIlyQ1zpJCoBp5z8+DJHyr5fl/9kpPHrfvAiJlxaVJCcH6fbJb45C0H2w71 X-Received: by 2002:a63:6d4f:: with SMTP id i76-v6mr6824630pgc.215.1536307289928; Fri, 07 Sep 2018 01:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307289; cv=none; d=google.com; s=arc-20160816; b=Kec8Os9Di2jFLZOw57JpfaeOPXKPOYXLEsGJyQuVAXe0MtIzX5HlOGJOmG5VgtVv7F TxMSlwjOb8wK/gCAxjqVkQCBVj3P5so+Z5WMswZ3EFOBBri5G8mXeD7bFCg/9hBYN8X5 YrE9agTOgJhALXcxDob0LIh/ELvdXnk2/hrUXStBe2QZy45q/4orgnLRRdM7jgLiGrkh RyUYeZLdn26AnHqt1x3UJEE/2eMvEQmU83iyvgbt9uxSGXWspjE0BJH+k38KlvvjuXKM r2SZGeqTPDZBmClPG9Kte6vfJOBnajSV7zMsuvACYY7CUp4M7OUOWJGbQB9KX4tQhqnA dxHQ== 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; bh=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=hvz+JwugDKzVssoSQJ9EoDSKycLv4wX78qPCgPIHyyIHSTd1HIAp+TPjeHz1RCzGws YDHpt6rL5JJmQ8Ck+3n8G9LYFBtxQfjGwst+1xOwzLoDKSQBT8q7C/ttm5QMnIoMMrMB VJRBurCV8g9T2PXznGtH7VSDIgPb3JC8c3DXKGgdwtDt7E69uDVsnvyb8Yre6NOCORf4 MqTEecvQxTvp50n0xOE3pmuXDqW+FwHvzUtkdj3fVZ6f1hIhMXDAbNJSy5bzcNFklp0w ZoHj/L55siFoZxXFNn69qtnqgWt9a204lxoKosLR4I1YoiMRBAoiuEz0N5+QBU4X6tkC lz7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JNg4+qmP; 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 e14-v6si7222098pfi.184.2018.09.07.01.01.29; Fri, 07 Sep 2018 01:01: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=JNg4+qmP; 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 S1728207AbeIGMlL (ORCPT + 32 others); Fri, 7 Sep 2018 08:41:11 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40552 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727986AbeIGMlL (ORCPT ); Fri, 7 Sep 2018 08:41:11 -0400 Received: by mail-pg1-f193.google.com with SMTP id l63-v6so6595336pga.7 for ; Fri, 07 Sep 2018 01:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=JNg4+qmPrhqL8pI8iQK66/MOP/PlN0U7kyxGs5tZ1O9HlEX1oOhHBvPqrkMp677Di6 WUCk3qUKzfoHWcnOlZ0FJKGvHlU5PrY9Sw4aklOpAAEO25wHy/OdoLz/qHzao1zzkR2Q JZDnMksWJ6LEm0z1w+idwhcItZMumFLDpBwDk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=orhTDLVw/rnCaTxFONHGbEUlBrEKuYIc/i/gkk5i+Co1iAAyL4bdCTaB4Jn7ro9acF 6eA3XKoD4tUdGesBxQX5QVucIHJ7S1P+tVdw+TF8VoH0TQ3jDKmBFc+hgNcnXqX8Eg/N WtynKqQ9TzJhe3NMyd6neWzSaFbS6tr0AkrCKSXTvPyYUwdP/hA75h8NpadYvTRyKOPN Mb65Vl60fN52FJURkt0HV9BfF1y9o6DRc7otCySxN0rjnkcFBocY5lrkgZuYpKPTQ+ng XygIqJXnyDsLq6P1cxwTfqMuCFaCU0uvtxHiOTMhUWPzv2bodp4TA1jgk1qferISA+MO r+EQ== X-Gm-Message-State: APzg51CNOhitFUNAg/z2gftFeHPLEeXY/1ZD2Tbfu59xJAkM7EODLMcv HTZyPf855T5qva1HQwTUg35Bqw== X-Received: by 2002:a62:455b:: with SMTP id s88-v6mr7046964pfa.203.1536307286115; Fri, 07 Sep 2018 01:01:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x23-v6sm17566759pff.9.2018.09.07.01.01.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:25 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Fri, 7 Sep 2018 17:00:37 +0900 Message-Id: <20180907080040.4967-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On arm64, purgatory would do almost nothing. So just invoke secondary kernel directly by jumping into its entry code. While, in this case, cpu_soft_restart() must be called with dtb address in the fifth argument, the behavior still stays compatible with kexec_load case as long as the argument is null. Signed-off-by: AKASHI Takahiro Reviewed-by: James Morse Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/cpu-reset.S | 8 ++++---- arch/arm64/kernel/machine_kexec.c | 12 ++++++++++-- arch/arm64/kernel/relocate_kernel.S | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) -- 2.18.0 diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 8021b46c9743..a2be30275a73 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -22,11 +22,11 @@ * __cpu_soft_restart(el2_switch, entry, arg0, arg1, arg2) - Helper for * cpu_soft_restart. * - * @el2_switch: Flag to indicate a swich to EL2 is needed. + * @el2_switch: Flag to indicate a switch to EL2 is needed. * @entry: Location to jump to for soft reset. - * arg0: First argument passed to @entry. - * arg1: Second argument passed to @entry. - * arg2: Third argument passed to @entry. + * arg0: First argument passed to @entry. (relocation list) + * arg1: Second argument passed to @entry.(physical kernel entry) + * arg2: Third argument passed to @entry. (physical dtb address) * * Put the CPU into the same state as it would be if it had been reset, and * branch to what would be the reset vector. It must be executed with the diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index f6a5c6bc1434..c63c355e2f18 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -212,9 +212,17 @@ void machine_kexec(struct kimage *kimage) * uses physical addressing to relocate the new image to its final * position and transfers control to the image entry point when the * relocation is complete. + * In kexec case, kimage->start points to purgatory assuming that + * kernel entry and dtb address are embedded in purgatory by + * userspace (kexec-tools). + * In kexec_file case, the kernel starts directly without purgatory. */ - - cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, 0); + cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->arch.dtb_mem); +#else + 0); +#endif BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index f407e422a720..95fd94209aae 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,6 +32,7 @@ ENTRY(arm64_relocate_new_kernel) /* Setup the list loop variables. */ + mov x18, x2 /* x18 = dtb address */ mov x17, x1 /* x17 = kimage_start */ mov x16, x0 /* x16 = kimage_head */ raw_dcache_line_size x15, x0 /* x15 = dcache line size */ @@ -107,7 +108,7 @@ ENTRY(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, xzr + mov x0, x18 mov x1, xzr mov x2, xzr mov x3, xzr From patchwork Fri Sep 7 08:00:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146203 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1458278edb; Fri, 7 Sep 2018 01:01:39 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZyH3rlB/6wT8GYj36YY2l1ZOdPzTTy/8APz81hW4L+Y7Ju7KaQCaqkiQ29nwMhefvLh+2r X-Received: by 2002:a63:906:: with SMTP id 6-v6mr5521526pgj.92.1536307299023; Fri, 07 Sep 2018 01:01:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307299; cv=none; d=google.com; s=arc-20160816; b=M4rYpGLhxBmNoxz5y2z5z7Wqssly77SvK6onlk2GK+F/ysmXxtS+w8QzdgYT3mJa0H ECNcY+B37F4+aXB/w349LRme9j1DGmQkhs40cbLvoF/kIbctoDk2A2HujQe7qYdYCGd6 9fN3Apze/W9axz+xld+NvjxkC0L6jAxIunP1yh47aN6wXoDdCrhUi9G3Ajw64cUC+3MP MAoeoAeTEbU6QYxAQFTFNU0IWB5zPIP/AGLpnYJaryQPt/KS9irPGwUDJqfMIZiReOao 0VTt7kgC6CATJ3TxXYyfmPQl7QIQeuh22Qj6lj12woHC1OFcSI91y4Ud6D55nFN4CjXJ Tc7g== 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; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=z+9iax5nRgpxmhMpMrufwwasY7jq9mg+mT1TnoUYuwPKjLhysjHeucgwCsmhjYKMdj TlHfauvvmnfaWzgBe9vZzYx0zWtvoJ17J5sXktXiWdwSWK4mH8qhZiyeniTr1ns9vMb+ xgI3Rgbjzh+wRyGeW127V5bNbf3oP2RJbQfuFS1iSI7N2Izt2Ywi54p/bwcWWlxOMCEE F+DKZM4qAiogddjg9Zeidw0W+1V7p8SRtOpNyL9koJaj7PHSuvrbr8tZEAWSBjUghvP1 7q3Nsu22oBeJA/K29aHDUH0qmhVUcV6ivmcdGR4YrOPPpmZcNGp6uvRLxwlDRg8CSBT9 OfTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JyzLWOrG; 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 e14-v6si7222098pfi.184.2018.09.07.01.01.38; Fri, 07 Sep 2018 01:01:39 -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=JyzLWOrG; 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 S1728225AbeIGMlV (ORCPT + 32 others); Fri, 7 Sep 2018 08:41:21 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33797 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbeIGMlV (ORCPT ); Fri, 7 Sep 2018 08:41:21 -0400 Received: by mail-pl1-f193.google.com with SMTP id f6-v6so6246844plo.1 for ; Fri, 07 Sep 2018 01:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=JyzLWOrGqoQh8eFOMBUNRAUWVulDA6drih+fd8GjQIsmU3ep50Kcg2+k/Rp0wT1lc6 BwOLxrjdARBYQomVgaLzINl3jX/PhP8dso+o2a48YgTRkjUXOIfC7geUiJ8XDSjYfczY byVv4TTS5c6khfV1Lohapgo9TJ8wzjfsKZ4mE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=gUJzMseyG1FoXbAQGNewzFPyGbRDffCGDi7s+gH1iDMLE4qEd2vx4VhsFHIf0H0WkX CuJsT+Dv4iz+zQl0z5c5Nrb0fSonD9pgqgHJeqh4IEXP7pQef3rQ+YjxyjSGcWyCPjvq HqBI8EbZOjZS7zhFl2hkpAVogR9R6TtrmtYC4WtaGgLfyiwyY5dR/0sYAxU1OPXMA+Ub eZuen76r/UMCZ4iRXi3QHUPNgDTP7m7+eW/Ge4B1gq9IH+p93eQ29aq3qG0GFMMD//Bi r7RtH4APFX4WZ5ItdKesMBZVpACmblafhQVfqoyNAvIDl9SE37WHS8A8H1xzYlPcWeAc 9fgA== X-Gm-Message-State: APzg51CxtMRf++zaJMTNbhN4Sly4t6IRajtJq8GEkXMLmz3ccwbmmtjj Hbw3f4UcDhrxUWB06z9XdoNu7A== X-Received: by 2002:a17:902:c6:: with SMTP id a64-v6mr6713497pla.180.1536307296340; Fri, 07 Sep 2018 01:01:36 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b14-v6sm10811236pfc.178.2018.09.07.01.01.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:35 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 14/16] include: pe.h: remove message[] from mz header definition Date: Fri, 7 Sep 2018 17:00:38 +0900 Message-Id: <20180907080040.4967-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> 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.18.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 Fri Sep 7 08:00:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146204 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1458434edb; Fri, 7 Sep 2018 01:01:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbfLw0i7hsGBQ67uyV+mpY8xxcXB96pcastqGVajD+FXgJbAdJND4U+etyKRJ4z94eu+P/h X-Received: by 2002:a63:586:: with SMTP id 128-v6mr6887458pgf.169.1536307308436; Fri, 07 Sep 2018 01:01:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307308; cv=none; d=google.com; s=arc-20160816; b=YShxLfztVg6ZwDcT07BFKSJExEw3GhIxn7WEEWLtIJ2bRyYeQoRdjcM5ppPECsJ3zu hsal3CGzwqPEJBYxr0CURjItAtm5bRxmec5HNmTvaeFhDpA48EUfOmDDBx+OPtOT14pP 277MfcLKIP2qUWLof9k3plziCmYcH/m0cAEQy3pXYfYGegDIGtWe+tnR54cHhvp49IwP A/+0w0OnUkTJT43K9oMsfjqDQDrPXNzUPT320WJ14Exp5dgm9P7ZsrrV5PrN5+CUvuqn 32974Ikx9FMipmYmXwM0ZVLqA08bcIQtZtbBGN3O9A+757ceJE5pCXJ3K+jYxDwnTB1e DVjg== 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; bh=X+GJm3Xbex0yl0OP8EjZbRJpEMSGQ2q0tg8RxWU9Kqk=; b=fOICvZ4Z0C50uSCwDrVfDU04aLE2uxh3YSE7VUh35HtRS2paqCkMT0NSQdKdRlWvPP HDMKmkW78Zlm28rxmIT6ovmatjNiyxH4HnvLCATKM4Yqu0haWRECjIBwAqvUqJJxglwH c4TptzA9Q53Nai1eWLcJAnz6ePY7Jlvt5D/I6x2I7pJR/52VcAFdlk/Jm2rwJ4AY9tId tG3YjImSfDVCz6rT9cK+mTWih02lXIieFnpsDuo8MQ/SzgAsdTuR0clB3nvR6LV6JV0b pYYME9UZsB6tDjNvVk8NCVfyx1m8WJIzTP1a11DCnkBVVLtXLWPWXSqPwAZ6UzPQBQlx 8HQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="TIULu/RG"; 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 v20-v6si7945271pgl.249.2018.09.07.01.01.48; Fri, 07 Sep 2018 01:01:48 -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="TIULu/RG"; 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 S1728088AbeIGMla (ORCPT + 32 others); Fri, 7 Sep 2018 08:41:30 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42289 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727963AbeIGMla (ORCPT ); Fri, 7 Sep 2018 08:41:30 -0400 Received: by mail-pg1-f195.google.com with SMTP id y4-v6so6592297pgp.9 for ; Fri, 07 Sep 2018 01:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X+GJm3Xbex0yl0OP8EjZbRJpEMSGQ2q0tg8RxWU9Kqk=; b=TIULu/RGQB3wXUBgnC5RwUQ9/bNFnHHSDDKNtaFC+Q8/PpJxLVYEw28tUbns0p3F1L u1PsnlOT3uNO/5a7ZeZEKpa8FEhI8W/IQeNDmXKvPECPhg9oFZRuRJs9LJsfYkxL82ic 4AeW/x0IC9qVSA2Z9h3APE+d+YfNkSakbAPok= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X+GJm3Xbex0yl0OP8EjZbRJpEMSGQ2q0tg8RxWU9Kqk=; b=IRE7DsYdNN38ZPaKoYX4WjW1Gjzs26YB1JEZKiukqk5pS14/FHeeaPZIcuF7lSDHKc R3BxV9kvRR2TywaetS8VW1m3Wxkp9uKHRetcHDF57LL2OhM3891p3XIYC0pMuGVd2/5y qjcQRov/T4gJql7/9KVaXPVvceaGdTaESTTSM4uWNL4SP4TBZUE7zHJazp760JDzjMcM f8tetGM6Io1sh6zasBtQ8hl/IRnx+0nYZ+libkzPGc+1mVzcR/5aHfr+zczRCGG+nfO8 S09rTGTIKkidVwa5e/E5l85NyKTyrYOG9FwxlMxe5FCJWkPMcA6IPvve1xzkBCF7gyDF qqaA== X-Gm-Message-State: APzg51CTMQZIuQhfWV9RxLzAvywFuu5g7cUhEZUP26zhE6cW1XI1yFwH LG78WPbI6G8kYxNJcVM5W6TkWg== X-Received: by 2002:a63:4826:: with SMTP id v38-v6mr6907762pga.379.1536307304938; Fri, 07 Sep 2018 01:01:44 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r19-v6sm10530577pgo.43.2018.09.07.01.01.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:44 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 15/16] arm64: kexec_file: add kernel signature verification support Date: Fri, 7 Sep 2018 17:00:39 +0900 Message-Id: <20180907080040.4967-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> 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 Reviewed-by: James Morse --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/kernel/kexec_image.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+) -- 2.18.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 5eb18d0cb513..e7de9500bf0b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -852,6 +852,30 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config KEXEC_VERIFY_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE + help + Select this option to verify a signature with loaded kernel + image. If configured, any attempt of loading a image without + valid signature will fail. + + In addition to that option, you need to enable signature + verification for the corresponding kernel image type being + loaded in order for this to work. + +config KEXEC_IMAGE_VERIFY_SIG + bool "Enable Image signature verification support" + default y + depends on KEXEC_VERIFY_SIG + depends on EFI && SIGNED_PE_FILE_VERIFICATION + help + Enable Image signature verification support. + +comment "Support for PE file signature verification disabled" + depends on KEXEC_VERIFY_SIG + depends on !EFI || !SIGNED_PE_FILE_VERIFICATION + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index d64f5e9f9d22..578d358632d0 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,9 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&h->mz_magic, "MZ", 2) ? "no" : "yes"); + return 0; } @@ -102,7 +106,18 @@ static void *image_load(struct kimage *image, return ERR_PTR(ret); } +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG +static int image_verify_sig(const char *kernel, unsigned long kernel_len) +{ + return verify_pefile_signature(kernel, kernel_len, NULL, + VERIFYING_KEXEC_PE_SIGNATURE); +} +#endif + const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif }; From patchwork Fri Sep 7 08:00:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146205 Delivered-To: patch@linaro.org Received: by 2002:a50:c01b:0:0:0:0:0 with SMTP id r27-v6csp1458617edb; Fri, 7 Sep 2018 01:01:58 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaMLGSfDuBKr27cAW2jx9Uk0CwNJrdiEltjB6JbraJPaI0vDVaC2a4HVI1Rc0GDDFgLYVUT X-Received: by 2002:a17:902:be07:: with SMTP id r7-v6mr6578801pls.275.1536307317942; Fri, 07 Sep 2018 01:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536307317; cv=none; d=google.com; s=arc-20160816; b=TgBtd50ANvEMABwHY39IRR7jvteM/Hi9zvVTBwiDSQbqM8zuNvI/2wCHLoZ8OKhhc7 c9t/VUHHD0IHs1Yg7jcWgq/YnJii8LtQtPnaCJm/UsI7o0b+rEuPrNfW9kVuqjQqI7GJ Ql3WXoNu6iGCiHbjchSoqe3g+5v0WqJIKjrujmJzVrey3H2SfPEzsD6Tdq0Vb0BAjltN D/fRHgk4aGGr1fhhz3zaV2uaGW+iOryGWAG0BhCqXPwkNzwGrIfqrBXo7dJ2uKwrhESY xxgF9Q+RpV/WseQCFsRM3afUu0OYdu2BWRggfgrmf7tsi2FTzrpiMd+7Tf2Y9NK/q90h DsVQ== 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; bh=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=aD/TRk9qCJgnl2GHf9stexOO0tbgdqVtCLDr8HYkrHBLA4k108YcYyLmli5m5MH9Un NWPHi3ciGY6OpR1qQuskmuYAYKAtnrZuOBGTIRS38XwqxZH7lw9engq3SyIjNuH+5ZaC 4Av6032BP5oT1iniC5XALt2jpL9eRJOImPk7Y3wNJ0Wr75DDX5R7UkJgj4rOJpPiFw3/ U7C0NogJZs0iVy0d3D/OXkLQ96/ro8hDEOisxPIiac7aTXKIquG8s8Iqn888GRE2l9SJ qOAO4Tx1hgW+NTvM3yknN+nPJ3z8oYpR/XAIW4Lmxk6l5c9JUClh7EWahKYndQuaoenQ czYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PUuXrmrh; 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 v20-v6si7945271pgl.249.2018.09.07.01.01.57; Fri, 07 Sep 2018 01:01: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=PUuXrmrh; 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 S1728262AbeIGMlk (ORCPT + 32 others); Fri, 7 Sep 2018 08:41:40 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:35645 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728245AbeIGMlk (ORCPT ); Fri, 7 Sep 2018 08:41:40 -0400 Received: by mail-pl1-f194.google.com with SMTP id g2-v6so5274058plo.2 for ; Fri, 07 Sep 2018 01:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=PUuXrmrhzXKdXLed1SIuT8fjgiUdG2uDYfqr82pc5ulwV00S7s0y1ONHe+4D9P0HS3 Xa74+tT+vF3yEETwBlMtSnKWua/f6afVjTDULUfRHaQMYEoegvwXamIHA+dGYRpr9fXw lp/17gfVbPnFF3OVqd0Ziwek3IQizPPI7r8NE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=s0VDoMzTVt++iCfR1ZG/ludwkBr5fioMZatWNX4x+ZjGD0Dk26ZJ76c1hs3pD5UfmX HFQs5tT1nS6p6Znmi71vPveL5Ed3MC8xBCN8xkPK2D8LgN9VVU/2ZQwUkDSIXmXQ24RQ BugYqSwlpzSx5Y1rHTRRuR0nifq4c8vEDzqq0X4bk1czvLOw/63HDLFewtfrBUsNmF6J pi5RgApa5dOB10XIYNZkCOQiERTtG+uvim8CqZq6Ta7HQh0g8gWbYzyKVx7bQh5jQ9n+ bIqzQ3pKjS6ee1+7r6tiR7bLtgMN/8e6E7+PtUmQj+yYa0AfIS+Yrl2C0yhimeC8Ca4n XhSg== X-Gm-Message-State: APzg51BQCMFVLXdBoRLmh0WZGZhBbDJZyX/tE1WDdBc/MYFaaJmF6zOa RKRODU9pb17x6VosqCh3s748Nw== X-Received: by 2002:a17:902:6b47:: with SMTP id g7-v6mr6800958plt.128.1536307314969; Fri, 07 Sep 2018 01:01:54 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 22-v6sm11078582pfl.126.2018.09.07.01.01.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 01:01:54 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, 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 v14 16/16] arm64: kexec_file: add kaslr support Date: Fri, 7 Sep 2018 17:00:40 +0900 Message-Id: <20180907080040.4967-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907080040.4967-1-takahiro.akashi@linaro.org> References: <20180907080040.4967-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding "kaslr-seed" to dtb enables triggering kaslr, or kernel virtual address randomization, at secondary kernel boot. We always do this as it will have no harm on kaslr-incapable kernel. We don't have any "switch" to turn off this feature directly, but still can suppress it by passing "nokaslr" as a kernel boot argument. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/machine_kexec_file.c | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) -- 2.18.0 diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index ecaecb122cad..967db9824e3f 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" +#define FDT_PSTR_KASLR_SEED "kaslr-seed" const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_image_ops, @@ -45,6 +47,32 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) return kexec_image_post_load_cleanup_default(image); } +/* crng needs to have been initialized for providing kaslr-seed */ +static int random_ready; + +static void random_ready_notified(struct random_ready_callback *unused) +{ + random_ready = 1; +} + +static struct random_ready_callback random_ready_cb = { + .func = random_ready_notified, +}; + +static __init int init_random_ready_cb(void) +{ + int ret; + + ret = add_random_ready_callback(&random_ready_cb); + if (ret == -EALREADY) + random_ready = 1; + else if (ret) + pr_warn("failed to add a callback for random_ready\n"); + + return 0; +} +late_initcall(init_random_ready_cb) + static int setup_dtb(struct kimage *image, unsigned long initrd_load_addr, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len, @@ -53,6 +81,7 @@ static int setup_dtb(struct kimage *image, void *buf = NULL; size_t buf_size, range_size; int nodeoffset; + u64 value; int ret; /* check ranges against root's #address-cells and #size-cells */ @@ -85,6 +114,8 @@ static int setup_dtb(struct kimage *image, /* can be redundant, but trimmed at the end */ buf_size += fdt_prop_len(FDT_PSTR_BOOTARGS, cmdline_len); + buf_size += fdt_prop_len(FDT_PSTR_KASLR_SEED, sizeof(u64)); + buf = vmalloc(buf_size); if (!buf) { ret = -ENOMEM; @@ -164,6 +195,20 @@ static int setup_dtb(struct kimage *image, } } + /* add kaslr-seed */ + fdt_delprop(buf, nodeoffset, FDT_PSTR_KASLR_SEED); + if (random_ready) { + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop_u64(buf, nodeoffset, FDT_PSTR_KASLR_SEED, + value); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + pr_notice("kaslr-seed won't be fed\n"); + } + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;