From patchwork Wed Aug 1 07:58:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143247 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp548543ljj; Wed, 1 Aug 2018 00:59:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcwHn/N8OkzcXdA718WBX2ZyQAvsAGRC/OHFwXMVBqR2NP9L/ozhPJ4Z8ts07+9xffjRPCc X-Received: by 2002:a63:844:: with SMTP id 65-v6mr24146795pgi.406.1533110374282; Wed, 01 Aug 2018 00:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110374; cv=none; d=google.com; s=arc-20160816; b=kBGbI0JNg+FXxl6FVPMW0Ze4XRjMNpJTh5ZA0YU5gZ1rnC5vWC7+URyDwC+kzVo/sG ETo+PRA0NgWkG10F1547DYWn8Wi4rdrY33cSf5T9Z/N/+sSCTq5Y2iCD1OX5dI089TY6 DnzDvlJOfYsXH+RmYwMR4tQuAdFCDZ7xcB42mo9VjyFD7URkUHfZUKsyzjz8x7RC8bFw oo+9pq2vLDG628zYwel/4xSf27A1DUY7ykgih+oboHatk4Ug9RUOCPCHB7IPr09pw32k gqgORFFZeuOtVz9FtfXl11C0e+AZ1XhwmcsSVth81bf58ua0ymAPVWZg4oUIeB3U5UYy Gw7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=yZcwlu+5P9xpCE/52qCzSt/LFt6IXmcu33O85YsCtfv4Ozcevw6nDTiDrLsjgZW8KD 17+FcJCea+dy2bHjy27/8XarjLLQHyFLy+GNl+k7MptUqLnA/8kJOkg53GjqlakcDfcl QBTvwRBij5yBlQ2Vi0hmN2AtxnCvvlGUU/Q7UtgAjorf56s+iGMYIOXZ758TNgIg9lPJ iu6jbgt+DKWhOl+tIbYj6N2j77bqqrkA/Y5PnryMfkqXgRaBjdwI1ytYe4DQo9/tu9dQ gBbDO3jgRxjdMbnMJOp5PfnAk9XkXUhqUa8jMnWVayfnOzKkuL0EJl7/8SI4DGlYSrkp EVZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CJMXHZuF; 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 b184-v6si17276099pfg.94.2018.08.01.00.59.34; Wed, 01 Aug 2018 00:59:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CJMXHZuF; 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 S2387781AbeHAJn5 (ORCPT + 31 others); Wed, 1 Aug 2018 05:43:57 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:41098 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387605AbeHAJn5 (ORCPT ); Wed, 1 Aug 2018 05:43:57 -0400 Received: by mail-pl0-f67.google.com with SMTP id w8-v6so8409926ply.8 for ; Wed, 01 Aug 2018 00:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=CJMXHZuF272lx6p1FY4vncZVgCLe5vB5pCCZOhKzIKR+dFmQ2r/BxKJRfYB5oeQUzz VfrsvDDunR3HDwVvUEILpaMpzgfFeDVqwu77PXdIdQY4qWW3tbsFqyEKw3rpPSiUKb9N Tkh+9w1KLuhKxTJCChfXdSjEJ38fv0SFB19+I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5amHDmg026JB1zJ+Ct9rVxm5mNHAXQC5qrpdWEXy5zI=; b=ivtDGLPqS5zVTl8zW1P2CuSYLQ/S0FnWrMak6/x8S3N7dXqwbwtP4Psnz1AtWpvXKU /wySeG5rDwxRHLP+cmEAEz0uNcSScxdSeB2aR3OP9JOMez+ZGDu+jfSlWpb0LgY9VCFM GAcH39/JPxnfuO2ewY4uCXZhRTAwu6pXj7a3nKeMmraR8uSkGTWHNvfwJek0n9IS+jga S2rq2XYLNmKCGlA7JoyiwwgVbf/BYW19LnkoA4bagcoWNucbWbuRcvjLyBldFRyINVQ9 hmI8JRop2F2SFlkSVtSxnsuMPgbYytevSsjwm7JrS3NRuBKShRxFJtqYj+JrUhABmj8j gcUQ== X-Gm-Message-State: AOUpUlFM31tO6DEoDCmPpLLdpB5eCdMCuA6P3Db4IqHCvTkDjCUa6sqV nXUEgVDzusqTcN6wSwvu6VSnVQ== X-Received: by 2002:a17:902:b785:: with SMTP id e5-v6mr23561403pls.339.1533110371491; Wed, 01 Aug 2018 00:59:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r81-v6sm28580218pfa.18.2018.08.01.00.59.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 00:59:30 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Wed, 1 Aug 2018 16:58:05 +0900 Message-Id: <20180801075820.3753-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143248 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp548652ljj; Wed, 1 Aug 2018 00:59:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdzDH6mVYXMh21liL55eNY5/ltsgo9BCkeYVtsxypx31vB+xDG4yPidkljnUBRGBh0Gzb7M X-Received: by 2002:a17:902:4201:: with SMTP id g1-v6mr15901113pld.203.1533110384561; Wed, 01 Aug 2018 00:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110384; cv=none; d=google.com; s=arc-20160816; b=t5/p26QJ8IGnj6kI6LWFbOeBsOBI2z4pHIYZp4GPwqVUQXtFL7WedXqbTHvjg4gZEs 9JQFlo3PCBxrf4wk0bOyWN1ITziTl60fP2kMSfHD35de20CxiPXYvQCkDA6xi7LO+p8H sq0q3NeVSWmhZYYeJ14Kh7ilfutK5MX40E+YLEUukb58/CmjJYuTzjFIO2P83jIIjvIB 2hwiL8HCuEeMfFUHRudHK5zoq4faCG4dVTQEuzesHaCQntK6qYDdNyc9KAfjZTHHyDAs L+JJob/zA37YFtqEKptMKvKosVBn/Umu42fEskkLx85OTCcfKze+jQEDyLyw4TPsd9I+ QBug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=s2mO4pdx9Fk/KSu/xK/tR71NtdinLFupWFEZ17rN65dAdsyQeSiZDT75T+66BN63xx Ig5PObo7Q3aMspmNxAkfszRYDk4DLfjEGkDX30BvTxFFtK911wY0ZyxHzKLzqMe++lAq CZjPkT+MAWs/tIKKhxKcd7XzEWcw0xMIIpQy1v3K7+lh3ZNnyiAGIBUU2ZGpoRa/OpzI 7bmbUQWafn7LUJCtJqPr/W6as4Gbuc27OEYjvr/RaFcleGlIT/ZrJtWm2oFzIakQu/ee cRr9b/SwKlZXUqm1CyD81p3OfFvkFrQMwkOjReI51o9vXjq7cDqHsxEzzEnQDaCNNCzy /lvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uv6f8cOu; 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 b34-v6si3314639plc.170.2018.08.01.00.59.44; Wed, 01 Aug 2018 00:59: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=Uv6f8cOu; 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 S2387803AbeHAJoH (ORCPT + 31 others); Wed, 1 Aug 2018 05:44:07 -0400 Received: from mail-pl0-f42.google.com ([209.85.160.42]:39700 "EHLO mail-pl0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387654AbeHAJoH (ORCPT ); Wed, 1 Aug 2018 05:44:07 -0400 Received: by mail-pl0-f42.google.com with SMTP id m1-v6so8398240plt.6 for ; Wed, 01 Aug 2018 00:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=Uv6f8cOuilyrUsJMwLSlGkRsQmaIQ1ADH2CRLyaqS1MpDoCDg9EIg/Yyi8CKwZN531 Pg27JoHeDbf/rAIG+ng9/UAhO78LOa0MbUIO9GrNUNlODrSUcS5Q48gdezcN/n5aBrfv +/r0CXt9deoc5LYcWq5DhwNbdofl3xb/8IY+s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=bDeYDD3TJZR098e7yKlaJyJYP2Z9zhjeeoyj9Ei32nDyyzhChuJdyL5DkQcvn0Q40L XKfdg0Pgud2+hOyv/U+fEMSTDwXfHJy37p5+uYfvYHJGS+6uk86qY2/3zTiXk/yw5Jjd 2DDcqkN6D0/KGn4dSvI3xu3bDKhtS4/qpAUgK268fTVtn03orp6IWsQVBE4pnzeWtj50 oLCgeP5BtIzydAg1oCNtJg9VsG4GaJDkyBwTfDBFVh03CqW9JQU18waXKH8IZydYbBqK JxZsfkdk+j3yJrmLgvLrIAizjCj5U4Khns5mQwQEBhvOIGwOxnM1Nnnl1x5xtOOhsWd3 fK2A== X-Gm-Message-State: AOUpUlGL/TEeVn//g0PXjJWFYx6HFXIfTYqrrGv3eoC2GuYDGow5Cn2M MWQOFnftR/8TBgV1fRBJe2Ng9g== X-Received: by 2002:a17:902:5617:: with SMTP id h23-v6mr23475174pli.324.1533110381241; Wed, 01 Aug 2018 00:59:41 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r11-v6sm23617948pgn.62.2018.08.01.00.59.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 00:59:40 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Wed, 1 Aug 2018 16:58:06 +0900 Message-Id: <20180801075820.3753-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143249 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp548757ljj; Wed, 1 Aug 2018 00:59:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfxCqkGqKE46UoYuUCSGk56hHLbn4naEnfLB6KhE/CrNlLlDcI5gnTWeAUpVuzA+2Lzy7+M X-Received: by 2002:a17:902:7488:: with SMTP id h8-v6mr23788986pll.41.1533110392704; Wed, 01 Aug 2018 00:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110392; cv=none; d=google.com; s=arc-20160816; b=lXBL24j3ZLAGipJrdJVrrN++KF3+bqZqolZ9/zNOYu+wN4oC4MGaU+AxHra7to+wl2 BO+1e3+uCUPXcLddyvsuqJvtcPhlCW+M+n7fb4+XVR5P7BulCKgzq+GFh7Z4H0I8X7k8 4AA6PPPiPAcS6sfZn2KI4EnvlLZWKHpP5Oh6A2yC42Fj33lyhRpV1Cj1RWkglQBqKayC x7avdg545gtIPUcM898p5k80DHgpzaCM1pUkIP8aGwtMNjtfBSjwh3/sDlwCNUIEWLg4 iHi1e+i5b+O3+GP1dP+cT4kHxumGyEPasrFMQlTLt9oBDGvVne1kq+RIrL97tDP1o9oa aV+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=68DGwEYhPm491eIfZZ6KO/KX2jzukwPpQsbkiYBWDXE=; b=FKHpPHwzcVOhcqQPaKvpxlPUq+qmE24L96Qa1g5i+70AWVz3l1yjWLC6+clm9eE4qa VIPn8e6hoAjNUL0T6PK/LMlSZlJB92JU8m28V8ZiE8pa8Kmtt6iFM9/TCOlV6FESgmcf G+l+TNPqWb6tF8b91x4G5tBylNXSZhlQOhqU3zds6HFngn1U2itg0pMFFxb+G8qLmA8i 5yVUQT9FkPwGFBNonGKk1UaqkiDKc97eO2qlW4Y34mfbWZ7G48timCVeVPTD87Xi6W7B m/udELv1XdKwg5Bf80sU3EyAf4vw1EMwA9p3q+l/DgJHDKOpKdImyUSPfOsKrDJTLjaB C8LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Opukkf/0"; 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 n72-v6si16112353pfk.14.2018.08.01.00.59.52; Wed, 01 Aug 2018 00:59:52 -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="Opukkf/0"; 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 S2387850AbeHAJoQ (ORCPT + 31 others); Wed, 1 Aug 2018 05:44:16 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:44598 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387647AbeHAJoP (ORCPT ); Wed, 1 Aug 2018 05:44:15 -0400 Received: by mail-pl0-f68.google.com with SMTP id m16-v6so8404585pls.11 for ; Wed, 01 Aug 2018 00:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=68DGwEYhPm491eIfZZ6KO/KX2jzukwPpQsbkiYBWDXE=; b=Opukkf/0wWc9eGzUj6XgdTjU9cGErNSQjnL4XLZtEr66NATP3fC2Nd55/otDP6Jk41 LZYQnjeYFyqlGr+gcK9uAD+nWrfUWaoyoBG42/6bIST40Q2+NTrTDWXGA5plcmH2UbSn S+FFm5HCGuPvK9E1HKml56RfSWFQfIsB8b4Ig= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=68DGwEYhPm491eIfZZ6KO/KX2jzukwPpQsbkiYBWDXE=; b=QZlDjQcjhK9rmeiTrIB4FR9lsHTJZ/g4VTY/NXnbYiklPaScoUgG9ADsRKA9/qSw+n TD+JoU4CW8RFh1URZtbgJ8vRSqk6KtPsjU2q1NVN2lYUb0OzV2ckQdp+C6gRc2iIX+tj /qYGI7Epc5+C8SI0MQlBKvDy67qP8y3fhgv5im/vd4+CIJwNclcxk4rZrTfLXOcEVeMf rlc5gZsnR1eNAm/xwyStn8zyIhAJu0DkOXkdwT3kf7MIsWISlENhe4VSWs55OpYNNRXG PgeQFe/yMaY8otqRwopxZsy/9YX3yqP1OBuSQxnK5rJjRFwIyvvSCmPM2agvKJJtA5SS wSmg== X-Gm-Message-State: AOUpUlHwjGgwx3OEZ43B0WEKXjrxAqbjZHqO8OmBub6uVTZAeOguZbjf DxikPf7a5LZ3XW/KMDMzYqwMFw== X-Received: by 2002:a17:902:778e:: with SMTP id o14-v6mr15537568pll.198.1533110389383; Wed, 01 Aug 2018 00:59:49 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g7-v6sm21547776pfi.175.2018.08.01.00.59.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 00:59:48 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Wed, 1 Aug 2018 16:58:07 +0900 Message-Id: <20180801075820.3753-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 ---------- kernel/kexec_file.c | 4 ++++ 2 files changed, 4 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/kernel/kexec_file.c b/kernel/kexec_file.c index 63c7ce1c0c3e..bf39df5e5bb9 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -534,6 +534,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) { int ret; + /* Arch knows where to place */ + if (kbuf->mem) + return 0; + ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; From patchwork Wed Aug 1 07:58:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143250 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp548911ljj; Wed, 1 Aug 2018 01:00:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf2gzVqoSlbEiMk11/VNHBHnfSVsAo9Zf/NpryX5dF+R+gfhtTW7pVhhWUsAatEZaFHFfgI X-Received: by 2002:a62:ea05:: with SMTP id t5-v6mr25488653pfh.228.1533110404576; Wed, 01 Aug 2018 01:00:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110404; cv=none; d=google.com; s=arc-20160816; b=CdBjzcqXf8npY4a3wNmT0C2rGMB2AigEYkj3PRvVci94J6CVlhczvjqQSAXLJrLVYT y6Aom4PFfQ/xOXKyQ2CtTPwhy2mkUoiVQEAo+CE6yg11Xos3CMXF5wHAOrEfy9ZBMBJm RHMSJZiNGOrzukcRXborswF9n4vKVw3xjRHQ0QGLk/Vss5bCW6TbSK+Br0OnmcGeyPL+ eYVJPcQf4HVJAdpP0ix/uTBCuR595hAEjsiEvGVt/KgOW7AENH22qw52bnrz3r381cNQ 3Cn+xxQ/HZHjg+IaXRz9O6Y+WowQu4+w2s6c4OGzbEAgLWcKcCTpfx135rjMZduw9Op3 IUmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=xe+ptcwA2jG1hIMUvqrzyq16x2eFJronfOhv7p2qODs=; b=RIdK7BL36l7sXJiG/G03qaAyNJA6B5kTxmyz4ajJaZx8deyeMItIscEdxdNW8ZJSRY W35zA6aue2wc9AowfsyK/jbyv5kziK1qrq7/F400D1W27o8eJBuIJo2dNE7iyLrK+unv Nd02Hx4NLknE/8N5KcNLj+FHcYvArynCAfk6xYaD5+zQEhUfdZv2AOJwuLf7vqK0FsNC 4eH7saH9wSt0s5dlMxw4uJpkwnOv8EQ+HzbVv4DDJkOcuapUnee569x9WPJHSc33qx18 TacrK4TyjhiBYJF1WaXAG0CZItin9IMJDKKNMH/fKnjIgVWIzsNeqs4A55kj9uzOsfbO hxbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BSn0QXX2; 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 k14-v6si16899624pfd.23.2018.08.01.01.00.04; Wed, 01 Aug 2018 01:00:04 -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=BSn0QXX2; 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 S2387902AbeHAJo1 (ORCPT + 31 others); Wed, 1 Aug 2018 05:44:27 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43977 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387647AbeHAJo1 (ORCPT ); Wed, 1 Aug 2018 05:44:27 -0400 Received: by mail-pf1-f195.google.com with SMTP id j26-v6so7426398pfi.10 for ; Wed, 01 Aug 2018 01:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xe+ptcwA2jG1hIMUvqrzyq16x2eFJronfOhv7p2qODs=; b=BSn0QXX2DBmorvj8lIohJ2EXbUkxGkvf9BWUMTCPj0C+zsVYWHajL6qt2nEpp36NHU ivtJD62+dbbvT+3ey7XwnY86eKaD3mRNJG77m20YixjoQRDAp/A9VNVo5eYkommzuP+N dhKyRRvY41Udtd0ByQ+Jkr7UmtoDu4iGxn9qU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xe+ptcwA2jG1hIMUvqrzyq16x2eFJronfOhv7p2qODs=; b=eJqjVZvZ9xFAZ5dsUMKi4dES32gVZhfCwreMJEyhanAtwfDOKmY0JYFmgurSqG52zy Rpkgc19iVbtuwVplZYYvLvX5dOO9bbBZ0ejQf7qxHdMgb+LuvtEBXj/3uux76YbbGEQX wSL/i43XuGDTzfItepujz8ivMyKe04i418DJo1O01zZ7kCvWqwxJXA0W68NyQLAivp2g HHfqUBXWrq36TTbTsgJMXCgQpqN/RBeOA2/3aEGH1ggPowq/gGJfR2s5d7MECNxjYNMM VCWJmUcPW8LPG6Lza4DpPqI/XHoNUFmskYXNsaZjst7uZ/FAoSyAmw2btCM/c1ME3/oX 0Q+w== X-Gm-Message-State: AOUpUlH9cZgUvN4UK/HnDk2/kur0drGg/ivuiATNPcZNdvQj2afIxAsh bGA1VxxgUSe0ax0GeZ4wU/n8kQ== X-Received: by 2002:a62:25c5:: with SMTP id l188-v6mr25450400pfl.179.1533110400872; Wed, 01 Aug 2018 01:00:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p3-v6sm21954094pfo.130.2018.08.01.00.59.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:00 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Wed, 1 Aug 2018 16:58:08 +0900 Message-Id: <20180801075820.3753-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 0bd23dc789a4..5357b09902c5 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, return kexec_image_probe_default(image, buf, buf_len); } -/** - * arch_kexec_walk_mem - call func(data) for each unreserved memory block - * @kbuf: Context info for the search. Also passed to @func. - * @func: Function to call for each memory block. - * - * This function is used by kexec_add_buffer and kexec_locate_mem_hole - * to find unreserved memory to load kexec segments into. - * - * Return: The memory walk will stop when func returns a non-zero value - * and that value will be returned. If all free regions are visited without - * func returning non-zero, then zero will be returned. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - int ret = 0; - u64 i; - phys_addr_t mstart, mend; - struct resource res = { }; - - if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, - &mstart, &mend, NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } - - return ret; -} - /** * setup_purgatory - initialize the purgatory's global variables * @image: kexec image. diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 49ab758f4d91..c196bfd11bee 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -184,8 +184,6 @@ int __weak arch_kexec_apply_relocations(struct purgatory_info *pi, const Elf_Shdr *relsec, const Elf_Shdr *symtab); -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index bf39df5e5bb9..1073ef56a95d 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -501,6 +502,55 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#if defined(CONFIG_HAVE_MEMBLOCK) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK) +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + int ret = 0; + u64 i; + phys_addr_t mstart, mend; + struct resource res = { }; + + if (kbuf->top_down) { + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + &mstart, &mend, NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } else { + for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, + NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } + + return ret; +} +#else +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#endif + /** * arch_kexec_walk_mem - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. @@ -510,8 +560,8 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) * and that value will be returned. If all free regions are visited without * func returning non-zero, then zero will be returned. */ -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) +static int kexec_walk_resources(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) { if (kbuf->image->type == KEXEC_TYPE_CRASH) return walk_iomem_res_desc(crashk_res.desc, @@ -538,7 +588,11 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) if (kbuf->mem) return 0; - ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); + if (IS_ENABLED(CONFIG_HAVE_MEMBLOCK) && + !IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback); + else + ret = kexec_walk_resources(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Wed Aug 1 07:58:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143251 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp549048ljj; Wed, 1 Aug 2018 01:00:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd2RAsmxuZBXTvseq8GiV1+IkGqucpyV2h+dHyoYguFX+0Km9aBrZmqSm3ohJdrKcX/UaSX X-Received: by 2002:a65:60cf:: with SMTP id r15-v6mr23458801pgv.41.1533110412872; Wed, 01 Aug 2018 01:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110412; cv=none; d=google.com; s=arc-20160816; b=x1C4hG8SJhHefdEz07jizsU1wId8Fnf0jQOYnYaE/lUKdQXZjLe6pdAJv+KmxlcWbI t5KLxLlwPToaGnr57/POG3X1h4l0mZATdxU4Q83z2VFcPTZ0Hd1GprUyaTfVeaCrKvc8 TBn7TzQ2o4Hix6JM5RvKVhK0a20tyyd0LiEKa1hYSXLrhryGi53MhBIisVLe5X00Exk0 EGb+0EPAHhBWiqGaVEw9lTYoXgfXYZuvnDZIUQCbXmzNya5upAWOtf1BzC9gGvXwM7TL MkwRjXab1qCsvOZorODAHiNfEuDWFdHljKUnHUoMsEjCE0ONJKf/a4bh29PaZFGOuVLe 0U9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=H9V/pRhzf1RnH7rtjNBLRuYtR4l5xIhl8He5yhS2iQg=; b=mq1ViGKRBNwAjLaZyOR5qALDKdzwDkaVVNogUtKKZmslZAEb7QJVFjZyFi/gv3S3By UdeNGvgiA4uRUNNpoCdd+rggb4qgDWpADEX/nPOH7AuYJi3cd5u3VSnA0YjHf4YRmEss 5HZsBazqs/mCjwaJ3FtC9YtobawTwMaBnuc9t06womaH+XM5dwCWZLjYmU7uVCirCPuj pc9+dQ0fr7lDLIFjFkMxejsTIJzZ+WstN/9eLhY9ztyh9G7nHKcTR+GUo1sMALGQcyj0 jNFLCTxZN5pIm4dldreExDmIUcTLiiYMkeOlxC3GxmrYj4WekoyfJVYGlLRJ+sWj60JF IaWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dv6Ao5gb; 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 d10-v6si14094782pla.140.2018.08.01.01.00.12; Wed, 01 Aug 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=Dv6Ao5gb; 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 S2387987AbeHAJog (ORCPT + 31 others); Wed, 1 Aug 2018 05:44:36 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36736 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387647AbeHAJof (ORCPT ); Wed, 1 Aug 2018 05:44:35 -0400 Received: by mail-pf1-f195.google.com with SMTP id b11-v6so2254075pfo.3 for ; Wed, 01 Aug 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:in-reply-to:references; bh=H9V/pRhzf1RnH7rtjNBLRuYtR4l5xIhl8He5yhS2iQg=; b=Dv6Ao5gbCEtv75PDFcno/cC/X0jP0Kp+YSXjdpVy2ycLWc28q9h03Q+dW3/n3iDhi0 WzYC/SbZjSVaYgsCyAp3rEq3HxWR1dl8CJD6iLTGOYG1WdBTT3Y1Sw3PQJGYMbFDj1va 4y0hNmbkjjjgQt24IaFB+VzuDY/MYvhdnsC4o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H9V/pRhzf1RnH7rtjNBLRuYtR4l5xIhl8He5yhS2iQg=; b=bjH1dnQLVAHtZyHNYpB/CX/rdaTGnosfcjDdw0I0y/ABoTyQYIhXZEANyXa0izMphe QRFUcOuPclX/RcM7Do/3k+0FSUDF85PeT90YLYWFAMl6iMow17dPLk/jfAg26RRMq0A1 wHqAfW02/YOeACGsOVzN1zvkZ0ocvQlecyEvSZdPRFMHVr1KCSeaAwb6ZNlEGRnJZpln j+7UmyvDAl1TRlGqkfZQpjgIjT/1KzQm7emS9BKplBN5ElmXyMXP2GxfJZ4gqUmOhQkD NwWfnEaj58DHvsHxgHwBzCYQrU1fCo94NKvavdiwgcV2BJwQKUKI/Qig0KPqu9+Mz+Z5 M07g== X-Gm-Message-State: AOUpUlE4Oopg86iY9Hgr8lkYW3M0IVobox2vo/QQlKWjNbYVs3CUWS9L D3ftbEgoKxtnWfNo+pYBBaN68g== X-Received: by 2002:a65:6398:: with SMTP id h24-v6mr23529895pgv.245.1533110409558; Wed, 01 Aug 2018 01:00:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h130-v6sm34714091pgc.88.2018.08.01.01.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:09 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Wed, 1 Aug 2018 16:58:09 +0900 Message-Id: <20180801075820.3753-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 1073ef56a95d..370d7d8ff27f 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -511,8 +511,11 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, phys_addr_t mstart, mend; struct resource res = { }; + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, MEMBLOCK_NONE, &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the @@ -526,8 +529,8 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, break; } } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { + for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, + &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the * range while in kexec, end points to the last byte From patchwork Wed Aug 1 07:58:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143252 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp549204ljj; Wed, 1 Aug 2018 01:00:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeoLCMXfgHkAWjc5iSs+TkqiOK2Z4fMy6fg2+VsohVcvyhWedq3fPFUX96MChZBj+p7t1GH X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr23500472plq.271.1533110421751; Wed, 01 Aug 2018 01:00:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110421; cv=none; d=google.com; s=arc-20160816; b=T9tUKzaB0xHxgZspDjhLeXj4/SGStXObHDQA+lKS/mqDvXTpf0Fg/czRx4aI0kZDwc lRedbiu+Bshfl5xjtra8fRCiaMbKn4hgbfjyrva94B6xQfQ212kJpL23wzd0uGMj3CEK PHcgLHnqCs/Ps6v/ZBfN41r2Q+/J7FRNTpWAMHS+GiCYr/NHw2wW5uDm3BYdCOqRXTxp JpxsZlDY8XVdQJx9RfkcAdI6CHTQRBChSNFXBk8E0viYyc/fU/FO8SbEdzCBk7ECtdof f7nQU/Tn+UYExnjmfSXDnUYrCtZX+5wqdgoALGdTQAkwbFQrVp0ecJMkzfFzlh2vq6zx qV3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fLowSY6mJuob0j2AasYwzHifbnb4+IvdIDuIYU6ROck=; b=wWykIghdw03kQnj/aiHQ8JN7M3tUsan2dixyyzu7h1Dre/6s7bQFZ5b3An8j0rat7G 4eNf0L5Mw3zhkZhkhQPSJxOxp9+ZW9TKb3qOw5KmoQRJA7FjRFRI9MIMoI3hc3zmuUTU ebGSlmMaNbP8PE6JUK8EXbsQcZp0Ic9S9PV+lklSRj8ziNf9cBJGMKhA5Wx/0dvcDyVu 2LQokfxJ5gqDg8GiZsjHYKVXDdK6l+bC0TBoITjzP0hzhGjb35A+JTI8LCP74bSmM1Uf 1HtfIeI36emctL4m3YpaqBKoE6qGTVLw/El/oTB5t82dpZlkHSnvNhZqfCQankEWd3lf 7DvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H3hOaDS8; 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 c8-v6si17713422pfc.136.2018.08.01.01.00.21; Wed, 01 Aug 2018 01:00:21 -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=H3hOaDS8; 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 S2388086AbeHAJop (ORCPT + 31 others); Wed, 1 Aug 2018 05:44:45 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:34404 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387647AbeHAJoo (ORCPT ); Wed, 1 Aug 2018 05:44:44 -0400 Received: by mail-pl0-f67.google.com with SMTP id f6-v6so8421932plo.1 for ; Wed, 01 Aug 2018 01:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fLowSY6mJuob0j2AasYwzHifbnb4+IvdIDuIYU6ROck=; b=H3hOaDS8j/Rt/AB/RW/jmcBKq5R0eDYWCPfojUYOtNVXx1+uDbbdhODFEqq7MTGhNX qx/PaUQr2nVxCGOFifDySvBW8chTOklnAvvijFuskd0+qCGdEh3wkiThBBNhugWphatt 08uTkcFREfQVSd7tfOheDtLEAWf35gAEHjJyQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fLowSY6mJuob0j2AasYwzHifbnb4+IvdIDuIYU6ROck=; b=P1T1UuApMUfd8O2VhgJKoYVzrsLrgzltlYTG8cu2DlE2BzHlXbskStIgnvVgivM1yE quXjMPxRBeLb4OrGNHlQK9ULTaIMwj40vJZDyjcxoyDrqyy60KOwHSrbXGJmOXfi3mwI fKExsWLzrWpbuiFkwVqM3e9KFtFnYYu3B6KASxl/USWEjCd7FuBJzboYZQA94mjLvyTN 0cZTNONDF4IWK/VH5FrM0gATECK9ksNUPn32FcfxqQSGXyBQL+oUxw967NmChvbQe5GR 2eCvNSlFQAor5h02yC0hXQUlReoxZWXz6QT46E6zTCzf2EcpuNGIFz/RNiGW+PI8Ey/p rwxQ== X-Gm-Message-State: AOUpUlGhYMNEB/KPAiSzm9xAB/3CALR/a8uBJm1Ga+mLYOiZOCkTneRl p47BLSCBzYlKga2g3PzcjyHyXw== X-Received: by 2002:a17:902:8f93:: with SMTP id z19-v6mr23221318plo.241.1533110418466; Wed, 01 Aug 2018 01:00:18 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e21-v6sm36306037pfl.187.2018.08.01.01.00.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:17 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 06/16] of/fdt: add helper functions for handling properties Date: Wed, 1 Aug 2018 16:58:10 +0900 Message-Id: <20180801075820.3753-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 6da20b9688f7..f7c9d69ce86c 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -25,6 +25,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -537,8 +538,8 @@ void *of_fdt_unflatten_tree(const unsigned long *blob, EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); /* Everything below here references initial_boot_params directly. */ -int __initdata dt_root_addr_cells; -int __initdata dt_root_size_cells; +int dt_root_addr_cells; +int dt_root_size_cells; void *initial_boot_params; @@ -1330,3 +1331,60 @@ late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ + +bool of_fdt_cells_size_fitted(u64 base, u64 size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((dt_root_addr_cells == 1) && (base > U32_MAX)) + return false; + + if ((dt_root_size_cells == 1) && (size > U32_MAX)) + return false; + + return true; +} + +size_t of_fdt_reg_cells_size(void) +{ + return (dt_root_addr_cells + dt_root_size_cells) * sizeof(u32); +} + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + __be32 val32; + + while (cells) { + val32 = cpu_to_fdt32((val64 >> (32 * (--cells))) & U32_MAX); + memcpy(buf, &val32, sizeof(val32)); + buf += sizeof(val32); + } +} + +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size) +{ + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + buf_size = of_fdt_reg_cells_size(); + prop = buf; + + fill_property(prop, addr, dt_root_addr_cells); + prop += dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, dt_root_size_cells); + + return fdt_setprop(fdt, nodeoffset, name, buf, buf_size); +} diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index b9cd9ebdf9b9..9615d6142578 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -37,8 +37,8 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node **mynodes); /* TBD: Temporary export of fdt globals - remove when code fully merged */ -extern int __initdata dt_root_addr_cells; -extern int __initdata dt_root_size_cells; +extern int dt_root_addr_cells; +extern int dt_root_size_cells; extern void *initial_boot_params; extern char __dtb_start[]; @@ -108,5 +108,11 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +bool of_fdt_cells_size_fitted(u64 base, u64 size); +size_t of_fdt_reg_cells_size(void); +int fdt_prop_len(const char *prop_name, int len); +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size); + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_OF_FDT_H */ From patchwork Wed Aug 1 07:58:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143253 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp549380ljj; Wed, 1 Aug 2018 01:00:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc3oAoYyB8jWoaVbu6bO8/jr9YTnocwlsKxbamur9xpwZ02lmPNjXDuSeUWQ4fPO7BLHWST X-Received: by 2002:a17:902:3a2:: with SMTP id d31-v6mr24154394pld.287.1533110429896; Wed, 01 Aug 2018 01:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110429; cv=none; d=google.com; s=arc-20160816; b=Lw3eUBX1atOKfHDePHu01oQofg05UnkV/H9FXlJZiET/+8zJVxn9OWlo2aw1YzBlWd AvCMQ9jQLmYk5sbzT/ToB0DSb6DdADxZ7EivL0GOOqbN99yREonRVAam6nSSR17X7X9i K/xtM3Nd8XqOTc+LuE35WXofrOIhSAveDVcAjQuIQelWxCjzPKdp7G81fWCrE6L8Ayi2 TPNtpKwf26lIYtgXtuHjdDAcYPDtvZsydjZepGZ3Joj0+dD5xi2dc8uBomgewf9A3WC1 QUXF9XuKHjkQex77ANetTFN6KviNg8+tZJd0yXLrzgW0dci6dOhtQF6uZ0AK7c2pXwKo 2fOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=yWnxUt6YTTgqds7/BbMSkurU8hPYwXA8vJ7uiSRqWJJIgiWoTgclY8/YfrUzHREvIK DfS2Ejut1VYK/R4xehJVQ52sCrxvIdFu4DMJbCJOOiuv566gF3IBuNSzdhajxjPe1XMt I8BQiRUi/pE9f3hz9NrSGGRYety7+/k26H3KoBsYSbGmfj2ie0tX/xSXGhHAD+0GzQxD McLLFjFNYzKpjiO0L3fviaHnvEjuO+DHsfwiofcc0+RoeuLCmG7yWY5e63WBhVuQIxQE UX4/22QTsteFdw9wr2AfEGOrmV/rM2I31XrQ0KneVPREv0aU9sekTmrhyO5/jhrP/DHu oGQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WXTPUSFB; 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 q27-v6si15963999pgk.187.2018.08.01.01.00.29; Wed, 01 Aug 2018 01:00: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=WXTPUSFB; 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 S2388175AbeHAJox (ORCPT + 31 others); Wed, 1 Aug 2018 05:44:53 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35387 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387647AbeHAJow (ORCPT ); Wed, 1 Aug 2018 05:44:52 -0400 Received: by mail-pg1-f196.google.com with SMTP id e6-v6so10420376pgv.2 for ; Wed, 01 Aug 2018 01:00: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=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=WXTPUSFBAaJs3u7G5trMfLp5/+9YTEExILtRGBfs+IJe9vkg2fysxPnpMbwEl9flKD lmPW2tJJl3FVwZhHhcUrzrEVaAZzqxOAZdWJl0cn+FEKabJ78upRQuMSd/7x86eFBg16 Dw+52Me8FRGDb+FHMU+dnXOEvH1CuwLqEZdy4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=ncauYQQW7DJnUCfL35DFnpO+5F1bTRkDMrT+M24qR2d4MGOfUXaL1XmsgnTA2bk1I/ nHXvd73uj5DKMWD8CPt5xWuV7VL9YFVKbHmIPeVfB7XnAkj8ICMW5hSfvWisi0SZh2Hj Lzw40wTxVc6sp+W3EsdnAU9qi7y0U/oBGz2xTf8FvuFQgUGjT98u0ifhC6bIr2nQO/H6 5d/Zw5CCUFd8sJVWqRvKX5FEtT/bew50IUkxyADQDMbArRQD/lMvr+YPRdqAOSPzx+J+ gIUoA3de6mhUFFi/igZJa4d2/KvIOQeErUl+l1HAG+Gc+any2ZrfQ2fFd8vcq4aD2STm IMRQ== X-Gm-Message-State: AOUpUlENhhvKwz+CECnXDv03BbNCRwqjon46aspzJh6sMlmMJbCd/pN8 NKrqaAQ9xyILoycoVnWjeqo/jg== X-Received: by 2002:a63:ba43:: with SMTP id l3-v6mr22801896pgu.295.1533110426434; Wed, 01 Aug 2018 01:00:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q78-v6sm30613415pfi.185.2018.08.01.01.00.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:25 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 07/16] arm64: add image head flag definitions Date: Wed, 1 Aug 2018 16:58:11 +0900 Message-Id: <20180801075820.3753-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143254 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp549559ljj; Wed, 1 Aug 2018 01:00:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcIsOvkE1sJAghT2i1rzewTHjsUlUxOHlUymR3W/CcnhQR8g5I/4AdLKy2pIdNLLHDO+LwV X-Received: by 2002:a17:902:280b:: with SMTP id e11-v6mr23574229plb.298.1533110437791; Wed, 01 Aug 2018 01:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110437; cv=none; d=google.com; s=arc-20160816; b=XfkXuAqm1FxsEKQhpbMXJdXQpRZRmkpA1s0APO1Ti7G7gy1GiGLNGMZ+nxLAV9HMpj wWcEKyOX/4gFaKnCrq8RRfPSXXiMrjkJVgBr9Vg2hzqX0WwD8vuy9PEQlwiSsxJOpH+V dzNA/NqNv9kkpT+aScLw+a/r3UrK8EWxNiBmrJnLN4ansnWMygtvh/LPb6GZrJqXVVen lUeEdtqfAuy7HHEeI6j78qHZfWe7Y9F6KYZWzkIYyuvj+r7NdiE/jUnX339D46D9kQmI Qb8tu2QGc+dN1sG6Zhaoi3s9FDwNaEo0PxdOlGpaWb8rt0UtpRLmwhNPts5yLnGgzq0Q AvEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=gxCW0Bv2TBdDle1DNHbnORIbDNrWZQSGwLjDlvZYRDOP6DjvVl/QFwgaIl46SWCIRr H9HRsmjLb4s2Wc+ssFY6ICVwP6XBJ9ePIbPXkXV1OWNTzonbeakHDlkCFboJ2L5SUK5b HsMhR16C25iyN9W+qm0vzg7XCfYhjpCwn11Q3SVEVZY73KKQLUw0uALQ/DmIfdjXDYUw 9xt6zffi/+oYrbAoB4Jw8hcYcQoRIjsyaUfklRH+gk9e3G8VXUy9GJWSQYSrxYtvPV14 HupcrKwEftUo4b2B0q1ueJaUve7GKstfApY5Olhi/OljlazxDvBsUPvZLBFsYtRI/OVt nf0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MqqpJpBU; 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 s2-v6si17624531pfs.2.2018.08.01.01.00.37; Wed, 01 Aug 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=MqqpJpBU; 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 S2388396AbeHAJpB (ORCPT + 31 others); Wed, 1 Aug 2018 05:45:01 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42514 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387647AbeHAJpA (ORCPT ); Wed, 1 Aug 2018 05:45:00 -0400 Received: by mail-pg1-f196.google.com with SMTP id y4-v6so10409315pgp.9 for ; Wed, 01 Aug 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=MqqpJpBUvFp2lEvNJTwx9ZZ7YAwCgM8bOhVaSNxP2WpsLkQiPuslusADBhd+NT8pJh wY6LGOwsYr4Fmy4T8WtfjNNeb3rm4Z1Da/6snVjEoqCIyXPFkGz7syVHEB/P4EyEbfxX H40shOwKe4+WeIkwl0OBU1Mpl96yg9YBBBp58= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=n1KxbU5+TN3C8p1sChiw/CVCtdHM9U78RvO3h/HReEIjJcvMCWdGJk/ztHOcP2Wcnd Ci6o3YQ+Z0kDYitmgimDhuDoBTGWljMdcSnxZ4NO6UaYBqxDAPkG6GXxkSWbNAHwkZYv FMa7WODrGF2bHq3LqhAvq5h98LkSFtltZ6i5UJ2XmjpJHMHaPIdla17wGVoywRRYUJ7H xk9OQumt0aFxV3HX+lZ07I82GWulUxK9jxdEMi/sT1zO6psduMSFrwiDM/AOB4grevhl 6lav2OcsSp4cJHa6rPMFAz2pqgnHl10xCXg6QWLsew9375zYtHDk6KX9pddRU9U9LY10 cXKQ== X-Gm-Message-State: AOUpUlHAPcNC9gnPbSyF1B+DZLWBgXce1NePgxOMICSkJTPCNkPiRGVC ZQ0Q26298CC011RHtgvItGa2Pg== X-Received: by 2002:a62:f610:: with SMTP id x16-v6mr25875846pfh.169.1533110434107; Wed, 01 Aug 2018 01:00:34 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v8-v6sm9357075pff.120.2018.08.01.01.00.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:33 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Wed, 1 Aug 2018 16:58:12 +0900 Message-Id: <20180801075820.3753-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143255 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp549701ljj; Wed, 1 Aug 2018 01:00:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe13meWvOUpYI9FjHhbeH74QJu7rWZKQGiBiN8QB3f/rmash5RK0qtp1Z2V1bXN33JgbcBn X-Received: by 2002:a63:5143:: with SMTP id r3-v6mr24188018pgl.11.1533110446256; Wed, 01 Aug 2018 01:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110446; cv=none; d=google.com; s=arc-20160816; b=uZI9SygXlTmY2lvT29igEL1c3vpv9r2XyB5K4qaCTLb8HQbqq5+RAke6fI+3bl8n6O J9jiLGKSArkVX5a/h+eN4NSHStAXT8N+phJSrFbQ+ynQkY9cQZO6oFy9sodQHcAZWVnU H4dTkUgclZglGgMyqm23F4eTs5yoaegZ9KLvdtQ3jCtSIZa0GS9FOKxU+9yCUIhs6FQM 180p+FKR6WoDRBlSMKBjlUNVBzLmQLWZe6MBb5KRcUV4krcsYdxq93I+7eWrZo2MF9gc 6EtwUv0RWlnX0Aa0XyvnUnNq3afIrPz1NDuOAZ9rF0hlYQfZzmEf8eKosBtC1nN35qKc LzCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=zriOn+WEEg9EazqAOYJi2TzU71K/MV/o6JIIMj34rno=; b=dVB7naKr+oHIYk8nFEGZV7byZFzURnTG9hbvF1ZoIKs9PmrG1etM8ga0IuwQ9I+n87 4PcI7Nvk9gP7KUG4g+fGYFSL4GXWv1at3KJ0vuZlKcwQMDmyMngpJ1gDNWLU/mbVj9yH PSujskLgTfqyGJZYwLR9gSMvh+b4QYfjjok8DRf66O14MrqMMPq7x/TpUpPu7U9bjtkF vDWEihk+vL5svJExdwx8yp/cjf2SwJt65XPt+AkNjFaUgNPihMc/t5hDnQfEnx+3JaA6 NttzmlDjZViDqL52xSIOr0+RPWflUWW39JyQyRJ2lKW6/kyCKR2awYa1VJIisQ4TOeNn AZmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bvGOQIkv; 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 n2-v6si15154967pgu.103.2018.08.01.01.00.46; Wed, 01 Aug 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=bvGOQIkv; 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 S2388458AbeHAJpJ (ORCPT + 31 others); Wed, 1 Aug 2018 05:45:09 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42525 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387647AbeHAJpJ (ORCPT ); Wed, 1 Aug 2018 05:45:09 -0400 Received: by mail-pg1-f193.google.com with SMTP id y4-v6so10409523pgp.9 for ; Wed, 01 Aug 2018 01:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zriOn+WEEg9EazqAOYJi2TzU71K/MV/o6JIIMj34rno=; b=bvGOQIkvBmDgcU5RI5ZqVEOSB5GvKJdRU1fhcJKLV93+axy/cZ1PiiD3NNZDl/ziPl /6/wtfG6wc1FpL/b8nhxTUIIZ/s1R1Z5dokBhrcy8Tv/u8vTLYP9e/byweReQ7xqAfTx JkW3v0bv6J4jpyBeUp9+Xx+wJceiTDXkts/F4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zriOn+WEEg9EazqAOYJi2TzU71K/MV/o6JIIMj34rno=; b=V0JxVyo52u5cZ+Gl0xSn6RFDrHMRo9x3vnns44xs3zpCrg/AeSlFQPQnp9S+fbpXjX lsjViiBaW5WJ4gicfoEYnlipr8ddZyz7tFJnI3SRq0USRj7n3O213e5lRCLGqk6z2KvL XIdBOTnoYymxUT9w52zX7kwJA/kiBpFTPWnla+PiP6U8q3FW9yJPBmDsoMgqAhABIDbI 9re8IPt0nqo3VDhWCq0mmfjTIn2GlinzqBbdEe4YlH0a0JGhkLKk2aMlQaB8c5TH/I/J KvCAXOhiYXITN6Bm8hbdIF+bmqy2rnotZBJHA4Po498l6bEzvHmKwC9opAadF1WCTi63 iOKA== X-Gm-Message-State: AOUpUlHN9idp7B0LYRr3AZaqMRSD9wiwutUKqaltW/baCqIq783otqxv mB/dUQr0U55aGmhBsTsoeaaZxQ== X-Received: by 2002:a63:5d58:: with SMTP id o24-v6mr23983744pgm.349.1533110442712; Wed, 01 Aug 2018 01:00:42 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g5-v6sm5201850pfh.63.2018.08.01.01.00.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:42 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 09/16] arm64: enable KEXEC_FILE config Date: Wed, 1 Aug 2018 16:58:13 +0900 Message-Id: <20180801075820.3753-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 1494d5cfd681..5988e767526f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -852,6 +852,15 @@ config KEXEC but it is independent of the system firmware. And like a reboot you can start any kernel with it, not just Linux. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + help + This is new version of kexec system call. This system call is + file based and takes file descriptors as system call argument + for kernel and initramfs as opposed to list of segments as + accepted by previous system call. + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 95ac7374d723..8f1326b2d327 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -49,8 +49,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..c38a8048ed00 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; From patchwork Wed Aug 1 07:58:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143256 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp549872ljj; Wed, 1 Aug 2018 01:00:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfClNdtgZ0EpGGNDwe0lCwVIZTVQmS5k79T+QKgZdGXgxunQXQAKX0WkmzMLKNE6rqWeHH7 X-Received: by 2002:a17:902:9302:: with SMTP id bc2-v6mr23633878plb.280.1533110456068; Wed, 01 Aug 2018 01:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110456; cv=none; d=google.com; s=arc-20160816; b=Bxi0nUY9ODH3EnOAar+gR1xH1YkdeKTQMMNcUOxkvAhmI8h05MFA7woOikSEUx7S5i lFluwnX+NzPWB9Juo2aZwypKQgk4ASk9EGxpN5RRJB9SjuOnR3xTYXhIP/TO7LRdsooT coyvdTm/OILuL7uSB5LVIc/0olR4zL+xoNOdlE/aFa6GSdEwZLG3oXgKAZJczvtjhy1K aMRcrZckv0ImBTQR6DPKvBvQKxv6G+jJX1isrE5mJpj9ymtJ+/5zU1gbrfvw6ASdqLqu hRfmHOlyhywCKGDyQfrVj8Bqj9VzvnHXIbLgz4g25bFBYEcDVnQgPjTCs6/zkrF6ePso z3SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=tf+vXLCH3jd/EOUUgeX5VCu34Ho6rX+LNzP3AsyVNX5jQx+QuD3R35YnSXnM4Op7hQ hvwF5Z+WnOR5QMkgORHq0/nTRgbdFimJgUVgQoteAEQWD5wqn8TsAQEXIy88z0FqAzVa VGIoYSyOstUTqoLB+pk8DopObuk8GMRZaQIqz1duC6tDDKHK822lFh/X30L6wAzWV3iP md/L+5r1r7m/6JID2Co9FtUxkP+8mjCusOVPeLM6PecHmfjfJQje/Jf3DfDvLAHd2VuY uxQD7x+WL4uaXRt9sHGsE7z0aFO9B+jPW84UsT9iSOl4nrSaMSv/TR0K85lpuA6oV3z1 ImbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ThvUzo7N; 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 a21-v6si15488894pgm.417.2018.08.01.01.00.55; Wed, 01 Aug 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=ThvUzo7N; 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 S2388485AbeHAJpT (ORCPT + 31 others); Wed, 1 Aug 2018 05:45:19 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43020 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387665AbeHAJpT (ORCPT ); Wed, 1 Aug 2018 05:45:19 -0400 Received: by mail-pf1-f193.google.com with SMTP id j26-v6so7427700pfi.10 for ; Wed, 01 Aug 2018 01:00: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=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=ThvUzo7N/mywR8+KG5HpBwmfPqMjQw/6kSvpVKlXOIHX/bZTgn77FYY3C+4v+WoN8S khpEPvhAPCWbA2ZWcnBoAKeNeQBJ9WAJ/7UotxTYhazOzIa9QFjuXO09oTOyM5HY0sSn IYm+vXl4osUnWA6IwsewhJSEd+BqWDipxUxsU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kuvWS+UEUvQZ2xoTaqUxXfZ4y4Bfqw3nkDkVU5NcSio=; b=dXMOE0+uXSua1W6vWO+kq0lOK5wd4rAba1KX5Bou20cTT02m+tlR3Yq5xdjUGytNSP WdVDP9btP6TK47hz2iTX0LAJ44UT5o4ZXmzRDq+hRaQP+P4TM2fj2LsbIw664ClpmjUh L2W7pbR3WcBAgHKn+txFvwv/TdN59jIgK8s6rXIul2VB4tQi2jYWWQ7QU15OsFZkg1yZ AqnS/ZJ5EGy8k198vzt0dC7xOqUs5YeDXjACP61LbyODH4ee2SGGxjMEnIyCY7FFWQbl KdtHbBB9CEKHDRPb4lH3U9mZuDBeQl1fs8xMfNoTibJNQtBngo5+LiicbBTIdUcOMkKA ZUMw== X-Gm-Message-State: AOUpUlHDeTiAx+rDiXo5kQeADzjSHJ3QvmSK7FOAPXrttrPna7xEV6ST e0eqkNazP5MPJBZy1mCxUvbOpg== X-Received: by 2002:a63:5542:: with SMTP id f2-v6mr24034312pgm.37.1533110452603; Wed, 01 Aug 2018 01:00:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t76-v6sm25277361pfe.109.2018.08.01.01.00.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:51 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 10/16] arm64: kexec_file: load initrd and device-tree Date: Wed, 1 Aug 2018 16:58:14 +0900 Message-Id: <20180801075820.3753-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143257 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp550044ljj; Wed, 1 Aug 2018 01:01:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfiB+7RtlwdFL6XO2d3Kq+2w6mYM3QkjWFwoB1aFfaAHuRgS6sZTX6WFAd6JajTQ700MHMi X-Received: by 2002:a63:65c2:: with SMTP id z185-v6mr23210315pgb.276.1533110463850; Wed, 01 Aug 2018 01:01:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110463; cv=none; d=google.com; s=arc-20160816; b=zbm/pUxBytK+/Fy56r80pRm6szP0PN1p/U9BUv4MdD0BsN7+jkYLwJrcOImfcTYJhS WuUjAWIoPDM8TGDVHiYUxvy5B+Cy2fQunkwA6SS+tGJjFMd1ywFv6VTMeekBfLISZU38 sqpViEiLKRos7iqylSaJq6mqm4snsgEXagiptsAC47twuVtlV1EGTQqqPLkkhzDxV7p/ BKWhZSaYKQyq0biMZE7w0WdBqHLTXXUn+2pzzRphhw58LzH3MY4b86zIJxc80vuBle40 w4/ODuAYx6xc7Og9I3yvLgh2iXTaE5woYWu1SpWac7ArR0gtMN5Zx5J2Flrkk82M2CrO Cc6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=FCtv7aPuc2Q2nB5sShVpfue1QMSfrrs2eO1wekl0znTa+e9hsbebpgKJtSftzbfTHR azDXC98zmUtNwZ33txPHSLZNEVyusBA/6/+qwi1QQ7geD9l1xZz1VpcGKKBg4sH+6DDp aqbpqsJNrlq8Fv3M9lNjYMBG3R55kWcD+zd4tmx1XsteEaDBA62Ydq9+njofBFejYIFC MAAGPBDEUZZL0UQE3SpMlERAGS5yb/oYvqWjxYy9Uk5UXrEA7vvR4vTfznw7M2FYwcq2 41Our7cb0FXo/DUUn4bZFPx2xMsZ6EZJGyV0V7f8iQP1WaoxNmNDM9AT+V2Itwmz3HHV cRUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NwmscwYW; 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 q18-v6si13993645plr.134.2018.08.01.01.01.03; Wed, 01 Aug 2018 01:01:03 -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=NwmscwYW; 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 S2388517AbeHAJp1 (ORCPT + 31 others); Wed, 1 Aug 2018 05:45:27 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:33673 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387665AbeHAJp1 (ORCPT ); Wed, 1 Aug 2018 05:45:27 -0400 Received: by mail-pl0-f65.google.com with SMTP id 6-v6so8408247plb.0 for ; Wed, 01 Aug 2018 01:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=NwmscwYWhqZON8CZseKhpgwawplUbNJN7/b2gDIO+S3brOWLLrCVuT0HsDWjOI5tAf i/izdBfGKLCi7iukZUaomqzIUFXKMYv9aNs+WSxYU3bvXXU8fxmyb1YXeafnCHhd8oFw StriFjJ5JMjSHdVXfWvZ79jYjFP4OXFHYXgB8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KyUS6TzJ7Jh2ZgQG+yZL9wQAPjkM+l82AYNmWJn5tsA=; b=YWaN4D64E506aweLbUDxlnmfGH51sOof7UBdrUJLZ3hPZ+FPiW9VlcUW7nzBpS/iEZ JX2QOQ3WMNFUttuKBpu1lRLFCCsC1OX5S9PFTjv+mZiZAJV8/3cwl7JrkV1RSZca5+2K g/KSNk1WeLbTJcwRprMrKPPD2TEz14TMP/TXguKeBmAD+W0ilAeDnlJxzlU9XKr7WdDU AUxbDo3pvMmexRJUnrumhqXxAlNOliD4oUVhIsaQKewfbPyfJ4H8yggumiE7y/q141QH q1GiytA2V5O2gL+3EWfmemR/JzesHcd8lUukOl6iAemCE+Sd53YglqRZ4FA26nhzL0Sj g3JA== X-Gm-Message-State: AOUpUlEee5kEC1fZrEKZCiX+vmQjTqbAqZNN8YxWqsF016Khf2KS8YQr vc8jdad9FXrba95c7MZ4INv1BQ== X-Received: by 2002:a17:902:b08d:: with SMTP id p13-v6mr24237716plr.0.1533110460349; Wed, 01 Aug 2018 01:01:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w16-v6sm40801764pfi.101.2018.08.01.01.00.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:00:59 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Wed, 1 Aug 2018 16:58:15 +0900 Message-Id: <20180801075820.3753-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143258 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp550172ljj; Wed, 1 Aug 2018 01:01:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf9nZyEfwUxHiwtbp9EFwWIPfXmU+3Rmyy2pby1f5j2DaZquWD/ss4LJZ1q/G/QTia/Xhyd X-Received: by 2002:a62:2983:: with SMTP id p125-v6mr25922435pfp.128.1533110471882; Wed, 01 Aug 2018 01:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110471; cv=none; d=google.com; s=arc-20160816; b=cjSHmfwtbhjTEPVxQKcgiP4IXHmuiWCUmDuDPP6QZkOc4ZiIh4ARsS+gVFKS+nHPod GjUHUFKHmFnAP3GlHH5XEYrAsQypc2jbjD+pSYly8TGKh0A7MZiLlYzZVdI9/lw+Fb6l E35im8yLLWbAiPesjb1S9zv6Ut8In5106vEy/yRj6/b3jamo52FFXWTo7cNqsDapuGDH L7zNT9E5zHGwqqlF1wMn7cTdohaU1JsVTP+BE3DgU+Sbxh05MUprDYu7HB1Tvp+7NADn DIb0dFrHyweB2OsDL7M6L/X9ly7Orp4COxXRO9me9/pebLEAVWixGqAWciu+F1OsZR6x 4OPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=T3I6pH7vrowaY0Fn/+NiyGSe6gdib90LrfCY+c5l3Lw+BBpy1xHCOdcZwKW0k1fRXj kmBDoh4BFcrCsYznMSdZlkAkV1QhsbM8NU2I5WoxBoUZ1l2Ndt+dsIdnO+rZSeyl0deN s+PUjcvZXpZW/PgmD7xohS778ilCmfLxviMB1ban0u4IsjF/QQeKlr5chFSthDkX7zbn ZLQZlysqi06EsTMOMC+ePBGW0wAUBQ3nmsthomWmBSNnTW8iM/NN/RCrltiC1vzodi4l EJa+RM8NRA8N47MLSxZgtyumX/d3AP7yMDTF4WkIPi8Y7fNJowSDMkDv2XDzDa07O97L 3eWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gta+etze; 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 s2-v6si17625918pfs.2.2018.08.01.01.01.11; Wed, 01 Aug 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=gta+etze; 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 S2388532AbeHAJpf (ORCPT + 31 others); Wed, 1 Aug 2018 05:45:35 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:36672 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387665AbeHAJpf (ORCPT ); Wed, 1 Aug 2018 05:45:35 -0400 Received: by mail-pl0-f66.google.com with SMTP id e11-v6so8411453plb.3 for ; Wed, 01 Aug 2018 01:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=gta+etzeWi3Nx5jjttTNJzlJ8GPAKnWoahb+v1yzW24La5bc/QpxtkdsLbAT8GYsSq StlHZBWhGxPUkMd/8inqZlem6+PdGQxcTyvFlsa4kpHUMvHWYgr9LrK/BZq2g6NfW2qk kZYE8n4WhnY8IrlwHxemXTiFEXtDIcwMV1GBs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=swjjpmgZOQ5RY/bW+WB2nT2kYZTPmzcU4gU1mJtC0o4=; b=QktZNM/h//qhlni/46LnPvD3YDRSFt5X2eDNoZWYShT2XBB00BsLzWMRaZsFI3Wuta xpNyaamQSHHGyeC3f89oaXogD/zrSA5AMuJFwFOIzSkJZ5bFqYpFoq6o6mxhW1hbh/BE 4hD+haATLq0m0x3/NPOEK5ndvA+wKUkVE8NB8rA4Ev7QNnVp4218s2MaBgUXAsYEsd7E Td16BlyOdPNi5Nj4k/ZuypjhB62hpafIa4AJ+Ww0Nj9q0TVk3zgNe70MOheIOKEbNSUJ kv5iPhgYlf2jMLMCoZTpm7LJpFHQ43wXJyovT3iKiN8CHO+s5Sz5bh4vFUDiHCOEI8kt YY0A== X-Gm-Message-State: AOUpUlFzh5dSRPa9dykYzP7w9STsKBKDRYRg9DwBe5LzrjyyO+KTEt7n TGIS4NIKHo9/VnilP5Gygk1n+g== X-Received: by 2002:a17:902:b28:: with SMTP id 37-v6mr23369526plq.337.1533110468327; Wed, 01 Aug 2018 01:01:08 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z8-v6sm21955997pfe.163.2018.08.01.01.01.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:07 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 12/16] arm64: kexec_file: add crash dump support Date: Wed, 1 Aug 2018 16:58:16 +0900 Message-Id: <20180801075820.3753-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143259 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp550330ljj; Wed, 1 Aug 2018 01:01:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeFyT7VEUQFWwxlZXdJDdfzryWI7tWzZeaVDYjUrk+o+501DZW8ktAdmjx1lJBuPVCUO5nQ X-Received: by 2002:a62:4a41:: with SMTP id x62-v6mr25812231pfa.45.1533110479944; Wed, 01 Aug 2018 01:01:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110479; cv=none; d=google.com; s=arc-20160816; b=wLnCiKNzmwcbhOLj/XsI1QUbx72auRLYxxnsjEt9fNeMQr8MfhUQel4vqbOZ/F2i1A 5PdgruZslJsAl1nz5e13tRVkwPJDvCSNQfrkBorGOXJT7XVlAOZG1mxVCxDmoCjyxDGG /gfgp8BWN8xnFc/saEd6Gkqo0vBtXqxpV1S26im65hvovf7CCqygnSLRhqhpLSlzatIz MVpJSaXteLjTbLfbdGigFXI3sjPJ4G9aOdzhbGceLYUw91ZSFiDx80QSdKoaP7GepnhX N2R5uJ0xPQoBcQ+bs/jmOaI0JUSr32+EZtxa+KeWLl71mMUziknlNnia2ItwlgyFyHsE WamQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=lYyRha8d3cEYWQDPy6SS4CJS/e8ct/P76LWT9sRC1j+6Dbc3l0eUyDM2uTDvAWldZh gAYltm1kzMHtOO6+THkvZCQLV+w+P0pRWCflHfnItHfdGpXvR8pm5kGYVfL94KXdzTnc 2oXtP0DnX+OkKZjOf5WPyWZLygSX2LxVE/vJ/UZ+xVKFX6DT5Fv8PxDlr5Z7pGr9RDys dlmqUbU3wVKytOEzfoOgA0NMSF6N1Cs1vvdATgYJBvIfMbEuZFDCrPZL8AKj6rsLKrzV LxTbNeDDScO9G6XMeL1DOiswS/bVNR53Rth1Vs89OjDcYOsPFY39Ix5MfE1OBaz5CHIh rGcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bxrkEBZX; 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 p19-v6si16224604pgm.109.2018.08.01.01.01.19; Wed, 01 Aug 2018 01:01:19 -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=bxrkEBZX; 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 S2388545AbeHAJpn (ORCPT + 31 others); Wed, 1 Aug 2018 05:45:43 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:44713 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387709AbeHAJpn (ORCPT ); Wed, 1 Aug 2018 05:45:43 -0400 Received: by mail-pl0-f67.google.com with SMTP id m16-v6so8406656pls.11 for ; Wed, 01 Aug 2018 01:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=bxrkEBZXNqcYnVXYfofTMl+wEyc+V6K+tsKOHnDes2qAy23Bi/unqeMP5fXb4rwcwX jVhm3yJfolblrN6UpfKf/bEeYNx0fTKZmy/2YBAmlaKMiOzPB92Y9CvXIGkgghi5uNAr A0h7JdHDtZd9yquPU8REl7XYTwXvkyUm6fbZs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=51KFAHSuDEEmK4w4TivyntHt2pXOtgfAOE9+35vlvvg=; b=R29s7eJHlShOGeEoWe0huiN3aVQfU/gl9MzZZXacDJ1rPBGSm6iD1JDS7/uyKQJ4tD C68kO9JeTTubBNYa2AAY+Hyo8iEAn7DUO6rpY4INXVk75mmoJX8E4sNVbu4VO5Vevvfv fSgDumwtIPkuYARn3dnTd9iItyHAOgG1U5d2Ds7vIh3jGBUA5Qpz7DM8dk+isrKzU7yn NqCmzcDE9yIVxI41v9gD1O53jg1lUrMdDanDHZuf6PTcQt5VJyWfDfrnBTRiRt5OwdZ6 QBpuK6fWYaTKmM/sgVfBC8e7CUzotT44EGlmYryG6+vcaAaFxqd4DsxJkGOLUMRuxd9m Bzag== X-Gm-Message-State: AOUpUlFH8ciM9nbjOJUgq2sk/yVZ9sVf5DYMWE+3kaI1+Ao/81GS4Xc2 6mEuz8Z0c6FPpe7OUt1vpICuVA== X-Received: by 2002:a17:902:bd93:: with SMTP id q19-v6mr23484079pls.238.1533110476812; Wed, 01 Aug 2018 01:01:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v3-v6sm52649116pgb.54.2018.08.01.01.01.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:16 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Wed, 1 Aug 2018 16:58:17 +0900 Message-Id: <20180801075820.3753-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143260 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp550463ljj; Wed, 1 Aug 2018 01:01:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpekaO3ZAekv/OG4Hu2SYPK67DMhAhvj8UZOUyy6pexnG/vGZ1hH61IAETClxiED4Q6YdKO0 X-Received: by 2002:a62:cc4d:: with SMTP id a74-v6mr25858594pfg.200.1533110487261; Wed, 01 Aug 2018 01:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110487; cv=none; d=google.com; s=arc-20160816; b=h+GQgo6vXbneKYaBPnB9UycL3AKwAT2copnrZdvTzX0N4FGQMlbnZtW9QmhejykUed pAe3W1B1wL7e2XNPHv5HOkNqMMqspHTAB8t5XO5YGaYIdzbpYfAp3ayVEGZa+9sTcGiX 87BKruxaJjUWToP95HE0nnwlAunfDlPRYB59Y9AHoXYkyi6hodwA36HoqStpYEvDwf3R A1t3hC/PVtX11zkv4VkMVGmfxilOr1ftiLxF+qGtV4OydooFa4fMhlfFD+TH9s6pa1mn u7+vUIA2YBn/dlnIkw+JythKrxmqwJqBjoy3ULBH4RR+SIFr1MhC9prylTswTlV4tP5L R/Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=GoKali7qpCc9vAhjHzf54kVeD0VnMLg33enZAEs7YdIRrn0MMAtQvOdbsZWV0HLhKi 3I151Vq0bSQNf2ySz1EtNg5oQfCUpOvNouAGbzC4Pl8AgVz43CinW0nLlVIAC1UrpLoN wcjFxOSgEEFIwun+n1Q8Oajz6vl6RZWRuD3QNX5DwJ8MCjc1j3km04KhwOEo97e0QzeK aQ1ObZTviO7DzBPzeJhvQL3XRh8qDSB9vfBl1PFvF1/dpApfITKhoWY3gP4S5YFS8EVG Ipml1Mf7JVlxPudMkwi0MUQJ0rHdArf9zdxcQfv3/7mTyHtbjfDYy3ZftZo15x7PBuKv z2dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZLy7xhwV; 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 s29-v6si16599734pfj.43.2018.08.01.01.01.27; Wed, 01 Aug 2018 01:01:27 -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=ZLy7xhwV; 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 S2388562AbeHAJpv (ORCPT + 31 others); Wed, 1 Aug 2018 05:45:51 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39741 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387709AbeHAJpu (ORCPT ); Wed, 1 Aug 2018 05:45:50 -0400 Received: by mail-pf1-f195.google.com with SMTP id j8-v6so7434606pff.6 for ; Wed, 01 Aug 2018 01:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=ZLy7xhwVoIk2JGm9se9fVuenhAyqRTXpFLb3RWBSFKDbrsdyjwlSdoj3/mNPxXm3Pp ParJ6WCLkg44t7OIzVyYXHtfPrCIvmj6Dy+8H27lKfdaa9VMlXMX3zv7sJcs5eOzE1ip UCnt9sSLtloaO862KDPWAqGU33k02X9kuCryM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=mrlilSj1KAxDWA8XtMBeS5xUQc471gsfNCO27MI1+pEVNLASmKwgiWHsUiJlK/vHSp vSJ0Jz/UblR/K9ux3x/k+I5PddXmXkSFJOa/2hOwb3aizOWWTBHqyht/HvHNDPNYuhQW GM3erY7ymA2VEIDr0X8mvglof0zINnyxTgKXvd7wZC7H0mtS+qZBrwbTUE/y4zIXEYOi J7y1ZDDKnWJ68qClsezC6vbDG9wcf7xlmIq265rVPw5mq56w+aThboyZWx42jbDdtgCg 8zfdYEoLATd+EHf4LnjjNABwSINlPeQ0kXufN78HzDkI+SC63zjmNKdK6hcvH31kEPX2 K8VQ== X-Gm-Message-State: AOUpUlEZqiDjbj4jQLML+4jrmSzakPgvxfvxBeqZFTXGb+o9Kt6pgeVr yHAZ4sh9AyAo0/WoxWOZFAmFxw== X-Received: by 2002:a63:c00b:: with SMTP id h11-v6mr23123341pgg.279.1533110484291; Wed, 01 Aug 2018 01:01:24 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h24-v6sm12255971pgj.10.2018.08.01.01.01.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:23 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 14/16] include: pe.h: remove message[] from mz header definition Date: Wed, 1 Aug 2018 16:58:18 +0900 Message-Id: <20180801075820.3753-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 Wed Aug 1 07:58:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143261 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp550623ljj; Wed, 1 Aug 2018 01:01:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfYdyZHly+lbGQ7lsVl9izIyE8FpLKiuKNCKy8UR7IFEfSdmx0enKH+6x/GzYxuDgF2JyLT X-Received: by 2002:a17:902:33c2:: with SMTP id b60-v6mr23706135plc.11.1533110495642; Wed, 01 Aug 2018 01:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110495; cv=none; d=google.com; s=arc-20160816; b=g5xWOYhDCR4lsp0VRkARDqQeBK43IQ8XsPfUzoGvuQUQNGk31/SFlAJr8WjxKvcVit S3fxdywETAWkJV9Z/l1h3DnMzYRzkJFU0f5X3KEn2+o2xCILy6bfRf/bcN2rSXgoT/6t vCcHS4+t9mnlHihr+CUp5S14Bwmh2EFUrzAw9XeDLZdMN0c7SAgEaVzYMwWvkhjeoe0t 0BNNodggRokMAQI+eDtElN9a7L+CQeovUdD2kWV3AdqFi/CO67JP+GRkQTl2NEWdRXDi /LC+9Va4mr0rOVqkySoNfIAJddnIR7CBlz56yYP+82R/7BHqSrDEyYDiN9ZkzAv7xe2D +k/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=oNyPwIsjRhf+ZiEWRkmri6ZF3DwmBYxfrK8HfgRNf3k=; b=pjFG0lZCxIxDPT0I+ppxvkgULpZreKkBvL23P+p8liTEDRcHj+YPmWKBOnjHpou/3q DXpyQeR+saMeoWIKBoH7fcMLHD76SSRwHpIC4hideZV7uI8DuJzxS8oNF5pTJ+PY6Hla w5ezrb7ymdk6e6Q/++Bc8cyuRXqQX9kA4FCHP+/jTNuzNWzjCyGv222NQi7z2573wbFA 7aHBYaHA9Tje+AOwGosl0tmoeYaVsWYIVxdD6I8v6zDZa8JgDaL53feGPsRRYNndxY5d 6A84FUFgIvJ3ipwVXxsgU4+/4mJmr8Mr5gfBtFlxc8ogZeJWlpO+8zXaEWIPtPjoHVdj 2NTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZAryMb/q"; 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 t2-v6si16526050pgs.142.2018.08.01.01.01.35; Wed, 01 Aug 2018 01:01:35 -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="ZAryMb/q"; 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 S2388573AbeHAJp7 (ORCPT + 31 others); Wed, 1 Aug 2018 05:45:59 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44318 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387671AbeHAJp7 (ORCPT ); Wed, 1 Aug 2018 05:45:59 -0400 Received: by mail-pg1-f193.google.com with SMTP id r1-v6so10419223pgp.11 for ; Wed, 01 Aug 2018 01:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oNyPwIsjRhf+ZiEWRkmri6ZF3DwmBYxfrK8HfgRNf3k=; b=ZAryMb/qZx0OKViN+b6ys0hiRqPvP8zCaMkL4ja0xTPB2q0UloM4GrkKFV5wiuNO/P lzmiVk6zOo54gMHgaJfh6aAMPLrzSFlU1lJnzV9iWudQz1+ZVQGcFC61vdHQrXMJUwDG M5DdkZHpJc6iwvCF+yPRD9d5rvirOXYE1lYBY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oNyPwIsjRhf+ZiEWRkmri6ZF3DwmBYxfrK8HfgRNf3k=; b=FEGUk8yZB3vnDDjFqmkdF8kY2krrOxBvjsET7liuDI7Yk7I9zLzn9gStFmwv+YE/6o UymbwmIvNLV1NocMFxI4W8W1L0FigQ0C75cndnj4UuaRfnTkvsJRo05mR59L2so31O7l QycLX2eu6nrOGhuGgSwcWIoDpjLvT5x/sxGJoHckO0/bnIGe/7WP5wEw8023iPwlnYtJ 8xE1Oe+lvwKdRbQ5xJfOPUeQB9eJfkq5ULcPkZN9IOmKYwON8bb6ZNFyANVrVOipfg6b d0IHNkKFyv3sgbIhYghDLLD2XHa+fujy6PY+IWZq3UeKgxi6xxhRCL60OW07KZw9h87m mBtg== X-Gm-Message-State: AOUpUlH2wbOiOs6jnxeVV9v538MKI5oq0y7IF6EYkHMyKKBtW47y0WDS wkqkDjE3MzFRCqCH7fd3WDXdVA== X-Received: by 2002:a62:3a5b:: with SMTP id h88-v6mr25710062pfa.61.1533110492352; Wed, 01 Aug 2018 01:01:32 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 70-v6sm12694141pfz.27.2018.08.01.01.01.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:31 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 15/16] arm64: kexec_file: add kernel signature verification support Date: Wed, 1 Aug 2018 16:58:19 +0900 Message-Id: <20180801075820.3753-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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 5988e767526f..fdc4571c142d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -861,6 +861,30 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config KEXEC_VERIFY_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE + help + Select this option to verify a signature with loaded kernel + image. If configured, any attempt of loading a image without + valid signature will fail. + + In addition to that option, you need to enable signature + verification for the corresponding kernel image type being + loaded in order for this to work. + +config KEXEC_IMAGE_VERIFY_SIG + bool "Enable Image signature verification support" + default y + depends on KEXEC_VERIFY_SIG + depends on EFI && SIGNED_PE_FILE_VERIFICATION + help + Enable Image signature verification support. + +comment "Support for PE file signature verification disabled" + depends on KEXEC_VERIFY_SIG + depends on !EFI || !SIGNED_PE_FILE_VERIFICATION + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index d64f5e9f9d22..578d358632d0 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,9 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) memcmp(&h->magic, ARM64_MAGIC, sizeof(h->magic))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&h->mz_magic, "MZ", 2) ? "no" : "yes"); + return 0; } @@ -102,7 +106,18 @@ static void *image_load(struct kimage *image, return ERR_PTR(ret); } +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG +static int image_verify_sig(const char *kernel, unsigned long kernel_len) +{ + return verify_pefile_signature(kernel, kernel_len, NULL, + VERIFYING_KEXEC_PE_SIGNATURE); +} +#endif + const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif }; From patchwork Wed Aug 1 07:58:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 143262 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp550790ljj; Wed, 1 Aug 2018 01:01:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfOlI/FMoym5mimRC3p2W2NKWuXtTvba4qxsAN3580dmB4HxVaCJZBUJLWKpbR+c0GjcnAh X-Received: by 2002:a62:89d8:: with SMTP id n85-v6mr25470971pfk.83.1533110503770; Wed, 01 Aug 2018 01:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533110503; cv=none; d=google.com; s=arc-20160816; b=Ms87EwBryVTL3wQqIZ5Wevep37Bs0sOLK82BfkzN7IuATid5kzkFo/TCDsWU4yApBc Un5rl9GmVPlf7yZCdlDCXHOkD9hKON04cz/2OuOjHfvkHP/c7Sp39Im8L2kT8Q2rjtAn zFQDX3WKSFCqaxnD2S6m+HZEVrMPH/VkwE4ObnaeVITKkn9Ij7xEbaU8X3qhXwbjSv8r cNGUs/hVDd1WNt2oDAOkn8VT/QmcRVx25EBJxt6APat2CXQEyQiHuL6l5mrffZCoNGsz 6n31aIgI05fmcWgifE2BEy6CEormP2eSdYMuen73l4K+g52NQKGI1hqh0BuDvWc2qRC2 V/jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=K2xCQQgObrN3LfsX3LjSkcPo/a29tk5fdMawjmzc9iT66JcJ2NCM35cxW7VXkPc9lo zCyoW1FTFiNV4T/Wqg9tYr+fMTNjYE3GymwrQoNoumczcNvBAE5F1dGnf5l65s5FPZc6 8HWsU/2PZiV1bow5c7g8HF8xCMyIySOQg6VNgoCvEciKnsKiWtWAZ98oCTt8RYhIplTg k2kRIMCGhXcPMQm4ITA+sXuQ0Bz8tSEw/9ncj31I/GJbn6L0DUpLS2aB7ni0wuz/EVCk TMYGRybzKsGBJjFhf7dMc9Ny/Pd6dzZ0CMlYrZRJK0fRATJKcY/U90MNLQKJCWHEIU68 Jx0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WU9YMzQP; 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 139-v6si16035845pgg.408.2018.08.01.01.01.43; Wed, 01 Aug 2018 01:01:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WU9YMzQP; 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 S2388580AbeHAJqH (ORCPT + 31 others); Wed, 1 Aug 2018 05:46:07 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:41264 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387673AbeHAJqH (ORCPT ); Wed, 1 Aug 2018 05:46:07 -0400 Received: by mail-pl0-f68.google.com with SMTP id w8-v6so8412783ply.8 for ; Wed, 01 Aug 2018 01:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=WU9YMzQPUTnoNa5HnOw5eBPp1T5wlr/z+viQAp2LZ9cSIxO8ipv2mPcyWDp4ZgzUnT WyDkooAOOzxEqlB8kLCDABQO2QVOlRMhZB3KkEfJ6khFhMadGcYSqYRkkKUVjBl0VlbF VK+VT5wZGhXDfPxb5LJtU9vUnaUx9zApOz56g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hvAWBPxjHLCiuG/UDQDc1Nu8BX1v01gDGjuspChhtac=; b=saAK6TY3DBTkCmVUqdzuwQ9SNCC1150rj9tHYqhSEqDZPkc2vpCIqFJ82eNjOLiyTf lOR8sVKQCYZWgGddpvOHDXRvHVZjKuI8tbsm/6ufKk/9TOEBGHiamIkfKLju+vNo9+Ot nOWVCvExs4cYCCf/4CflHlBal2Q3tCpWkMxQi2eGWw8/l2QjSdgujhpRpLVcDVwnmHyw i+VG4R3P+v8V++ilnldcg6i/aLhiTTedwQ/y5iSkWJ+q30JDRZ2P6FX6160SsA7NfcY5 6f/4i/T12u73FECziBdkch475pqDCS/Jq3AarnwmsEqyfEpowL7Qwhps/YlviHfzW/vh ZXCA== X-Gm-Message-State: AOUpUlFT3+jXRyRPEotMf90jPl1T7/pbZd4nShDVe60Ptcde0oQaFOEm BQGgKIpJDuCqAq7de7Jz8cppMA== X-Received: by 2002:a17:902:e005:: with SMTP id ca5-v6mr23681465plb.224.1533110500350; Wed, 01 Aug 2018 01:01:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y3-v6sm46126520pfi.24.2018.08.01.01.01.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Aug 2018 01:01:39 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com 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 v13 16/16] arm64: kexec_file: add kaslr support Date: Wed, 1 Aug 2018 16:58:20 +0900 Message-Id: <20180801075820.3753-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801075820.3753-1-takahiro.akashi@linaro.org> References: <20180801075820.3753-1-takahiro.akashi@linaro.org> 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;