From patchwork Tue Jul 24 06:57:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142687 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6917853ljj; Mon, 23 Jul 2018 23:57:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfFn5niE4E1t64cudU19zZE75QUbW4MRne/EO3WyeRcyW1VhB5b742VNwQa8ALdorr+inmI X-Received: by 2002:a63:1d5e:: with SMTP id d30-v6mr15589856pgm.12.1532415434542; Mon, 23 Jul 2018 23:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415434; cv=none; d=google.com; s=arc-20160816; b=PZ4cSRzjnGGsPm74NbVwTWUWaANU0ENV+E+cUzLLtmWfeLrvtCxiatUHdebX5DE8oC d/RQSEPWAu7QevLznAQTGBJ69sR0V3J3mxeGA/mRXgv9u4yRn28KyYJZaqt4OF1/Cjaq sdBlHz97/VoP6iwPByM6mYNzJq6XrEPgiXWdxKVIYXCDffmup+EAexck5GBK4Afibd6A C+tZLM49X5dvGWyG8T3Oop6PZhG1E+gjEZYwMfnrAcR88XpBrx2KEpZ2z6/tDR2hM0lO +N+AkZtG/2TtH3akBvVl2cayfSdPNz5gd+LAJZ0+vyLI2b8egIYLq/qifG4nBCDX7RCT m5mQ== 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=BD5KBPTKxdMtpqygaHhbkvkazGjFD66/w/IEI5sq6YQ=; b=cNnlZgqslCA6aRSbdttGDA5doATmorZ43R/ZA39OftEmki6iw1QSLGBM/06b05xDa3 pFK2PANXtPIDOOks9ZmhQ0DaGyjzDEtfKmOJk8pr8XXao76hSu8oCLu42TnjouJvneBk HBbVW5Qe12GXc6npG8ongReHLKx09wizTHu//5LKn21l1fAFfH+uqv4yhwN+rnAQgIpi kGREoK2gq6lbXlCwnH13/11C48JeTZsz+gElwsPqyiV64nNmXQR3NgpjXqGC6e6Tk/Ae xp2XVs4oLULH9MDd7Q2yBBG5amQkN+TgBAbDeMyruokYTgHwZOEhP3kbe/VrfsDD63uI /NEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KSWf7dB6; 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 b9-v6si10073125pfi.99.2018.07.23.23.57.14; Mon, 23 Jul 2018 23:57:14 -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=KSWf7dB6; 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 S2388414AbeGXICI (ORCPT + 31 others); Tue, 24 Jul 2018 04:02:08 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:33841 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388245AbeGXICI (ORCPT ); Tue, 24 Jul 2018 04:02:08 -0400 Received: by mail-pg1-f195.google.com with SMTP id y5-v6so2195584pgv.1 for ; Mon, 23 Jul 2018 23:57:11 -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=BD5KBPTKxdMtpqygaHhbkvkazGjFD66/w/IEI5sq6YQ=; b=KSWf7dB62jD+2CI25qIfV0icHgEzVjhvX+daLfcydF/eeJeFARBKhZvS4pStqBy5zN IxWJ523bWypZMHdzMjDVeh65AD+AYBkRgUZ5NComIcmAXDFWKN+eFozGjPTSK3iG07Zk RBv+0SzD0fMx7hwfVqwmR26FtLw3uiAxqCkSY= 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=BD5KBPTKxdMtpqygaHhbkvkazGjFD66/w/IEI5sq6YQ=; b=PVp1/lmSa5Cpg34TI4Tgil6qK83cKps5dU+tMS3737afxlKP5+/cOzoLX+OA5mHAJK vMR6ConYDZl8rJ3rh7ztIGbCG2SX7x6qTGiyFzUacXgLTl5HoabuaVd5NkbFE9xup76U tF1XFJVMKfjZOpKOmVQ0Dyey+uKQOhi2K3YuCe3OzQdLwJrnWgH8YKhQsVuYWPjV1lny +LWG86RUYzPChVZYc3jllLlaYH4RgsDDBpELqHBxpMWsd4XWDTTNrQyRnj+tOa/wqOoV 9/j5jkg+foSwd1nb9dYOW3GIXa2oI4s5UJS1kA2EaXoUh4+bkLSbj+Pij570k+/tpN/c 44vg== X-Gm-Message-State: AOUpUlGorDeegoIIUDZZkWMORz6TyL6EgdVJshm8lpAOF3Kwaq93dieO IhAVxSkCz8mfQ2FKK/ZauPp5ug== X-Received: by 2002:a63:62c4:: with SMTP id w187-v6mr15035901pgb.55.1532415430908; Mon, 23 Jul 2018 23:57:10 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w81-v6sm21247538pfk.92.2018.07.23.23.57.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:10 -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: 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 v12 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Tue, 24 Jul 2018 15:57:44 +0900 Message-Id: <20180724065759.19186-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 42990676a55e..c81f4a0df51f 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -734,9 +734,11 @@ __SYSCALL(__NR_pkey_free, sys_pkey_free) __SYSCALL(__NR_statx, sys_statx) #define __NR_io_pgetevents 292 __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) +#define __NR_kexec_file_load 293 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 293 +#define __NR_syscalls 294 /* * 32 bit systems traditionally used different From patchwork Tue Jul 24 06:57:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142688 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6917971ljj; Mon, 23 Jul 2018 23:57:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcJkV1Lt+dwMuMGLTUVZCK/X9V80j+GX6dyyvCERmHRYl3HlEXD9AHgud5EAk1YQTbcVMCo X-Received: by 2002:a65:60cd:: with SMTP id r13-v6mr15139557pgv.232.1532415445136; Mon, 23 Jul 2018 23:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415445; cv=none; d=google.com; s=arc-20160816; b=r+UvWxfuJddowl5L/PAM7cphI/qXrpgQhO2Io+ucDaEuC2Tb8oqoD3XHkHWfkKiZsD MY2YNov1Yxz2WRFbnE2liPSZVdcUu37y3+kmkCMXavj/S/quBoC4M9w0lHQD8iUhyro7 ykfV7o1NZ+8aF8a6IJ/ZwC+OecB1w9+V/civ+X6v4HFeJFrEkI4aMaBtHOquYTp2WqH1 sZcr2LDc27KIEmxF2U0qJEPxz5BF6U9tQEJ5O4n2cL6SK0TGKDRO3p7p+66rmIOlo6KN K9wQEz9c/OzMB29JpsqUkdLu9vrdcgGI0A21RtkFkl0ACtfaRpAL0aRHZol0Eb/2nrrA IH/w== 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=Auh1lslZ/YZvI1+WxKKHdp30wCJG6HcZVeqIAXwlu86p8tP98wn236KGM0XcVmKj5t BrE2Sq0tTWXTGf27HEGjRs3zX2z7EI+jWQ5+8sJK5vCLwrdxomMDEZ16rOWYKkaD19Li iUqgwrYo5E9MYCNuzQDJXFb9fGlyQvfC2WICL+EguuBrPppjC4XlJYrl3GOgsYszFJwh QRIAFy1nfctWdCrLHr6WYQwDtJTKHnvFT1maW+WpocgQQVg8keO8oVTB0HFfGwVguYIi 0ERhMeMM5FkRisRc5x0jcYd/c3gHajK1xH1R5dUYYIKDSixTVj+gm0OgtOoXOwTZIUq7 5qVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cxgjVzY3; 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 q16-v6si2181825pll.425.2018.07.23.23.57.24; Mon, 23 Jul 2018 23:57:25 -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=cxgjVzY3; 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 S2388430AbeGXICS (ORCPT + 31 others); Tue, 24 Jul 2018 04:02:18 -0400 Received: from mail-pl0-f46.google.com ([209.85.160.46]:45481 "EHLO mail-pl0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388245AbeGXICS (ORCPT ); Tue, 24 Jul 2018 04:02:18 -0400 Received: by mail-pl0-f46.google.com with SMTP id j8-v6so1264647pll.12 for ; Mon, 23 Jul 2018 23:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DIzV6aso3cBbRwIPS8DL9LqPtHHeWZam6wO8uhZIhTo=; b=cxgjVzY3MX0woauM2mQ0DdwelCWnuhJ3LX8wat27L/s2w/g2I5byL+3gKHF6y9iFVA HSpNiUSQsbulmADcHfeQ3KBclHJadIajI1bNqZwznx3JvdbU0PnhNY6dpzou+JJTZLpa fFvq3a6BiD/aBwwtqo4dCjGCLHdqEb59HY8pY= 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=r3SLCsjVH2AMvpsY+Gih9vjqYk7za3Nv1kRyH0CWbwwOX0M6+3y/xHtFRpVji1+yL/ DcSKJEf89Pm+bZIAoTweurnnsG/RzbvnhD29Jx259fdckKdRNtp9pO1EAgndbjc87UWf xBQuHfqk2ulTTIl9ax7oTmkzLQ4vVU+Z/8vAXUAvYg5e+hv0o+QQ/ntB0dZm1rOaJiH2 Gb5sJkkqPmVFLUrGwXWgTBXMg8hFpJahgkYiinY4iWEoAJuYmsfOpwb0hm9ye8gNjAb6 pxxgaDKi6zURjxHZPBlXHajEm2kHGSC2oqmGtnl/wkMZR3xcf7cmjjAvSSiwM4BfYILd scHQ== X-Gm-Message-State: AOUpUlGdf94XQtcIHICoRzlLdaVMkug3Rv8m6s/1BL9zjhC9eBSEiC5a AgAclTfmgNaqC/DpVghjYIlhrQ== X-Received: by 2002:a17:902:8f96:: with SMTP id z22-v6mr15898099plo.190.1532415440585; Mon, 23 Jul 2018 23:57:20 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f126-v6sm15721472pgc.88.2018.07.23.23.57.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:20 -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: 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 v12 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Tue, 24 Jul 2018 15:57:45 +0900 Message-Id: <20180724065759.19186-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 Tue Jul 24 06:57:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142689 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918083ljj; Mon, 23 Jul 2018 23:57:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfr0il6+T7ybPsvs9lSuCPA0v+PnVQXToX3oLNkaywgEDuweSCUiAQXpvXfcH8YzOCt4ac/ X-Received: by 2002:a63:1e66:: with SMTP id p38-v6mr15010727pgm.376.1532415454207; Mon, 23 Jul 2018 23:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415454; cv=none; d=google.com; s=arc-20160816; b=R0x54C/1O5SqeizR2DPJTSFtjsbHk1whtEbW9ctjcJEBQx6omClc8RqWE8SkPkQP9o JITU7WyITK/DVgaJZbYW3wgLkWp7JD5qM0nWlt+c2a2H4pMQieg7dL1131BSGZ49dE7o LENYkTJOVgeyzt2oGoazv7ICnAzv3UjdzX+U5gyNrHK2vJQnbldzQpPUyAGlUMZ8y2x3 DYGiThMAnh2iMPTqtTZpQpXkhoYUv2XPy9n80Z61gUIGWS1FrLTioQjcfajw58h5pQ1s ysiXASFfVc4C4REZ+lui2lia9sX+I8hTnZgCWKNifs+3X8U6x4s/Cef9FyIrLDYGALYW nMNw== 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=8ScyWDBSkpDCeiO9xWIrh9E1Li1NS358S3v+0v5j+T0=; b=IEc3oBup6jZ7TXKHijDwVoj8sZbf1FNbmOs8UZBndaUYuW0xamIrrawMysrFaRtkld TcwnW8E3DCEdihIsaGidXz/IkJJS0dP5fAD4/ED113mZ+Np8xS/bgK7UALzqNxaKALMm fqkUxCaivh8WAP7mGxjGymJLszScPzKr+vEmuxSSozd2wYbo4v5p7MjWHPUCsw7BouCM zrEoLUC7gyF7PaiHnioi6q3lI96MNkdmCrsMMEbwY1u3T77iyTgpOpWY128lJPr70FXr 9m1Jj/a7bZOVRy8vTHsZkwqkxC7qSQePPjKWkQZ1bslgTUQqarSNi8hOvLTnxjihqVvd HL4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="iiggbw/Y"; 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 n21-v6si10291541pgk.307.2018.07.23.23.57.33; Mon, 23 Jul 2018 23:57: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="iiggbw/Y"; 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 S2388453AbeGXIC2 (ORCPT + 31 others); Tue, 24 Jul 2018 04:02:28 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39143 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388245AbeGXIC2 (ORCPT ); Tue, 24 Jul 2018 04:02:28 -0400 Received: by mail-pf1-f194.google.com with SMTP id j8-v6so621324pff.6 for ; Mon, 23 Jul 2018 23:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8ScyWDBSkpDCeiO9xWIrh9E1Li1NS358S3v+0v5j+T0=; b=iiggbw/YJZIAmCl7wpn67Ovdkz+pycG2Mg51R/BAaen71ZB0eRXijPEyRgy/mq7wcd vZuBl7F5EF5rXfpH1vpV/gyllE0ooG8GMxvKSqC0uAnU8aq9M42TGFGK7DAI3m1gVdH5 IQJsH+l9kVW4XYYkiCKC0zQ/frf8WjM9ggA+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=8ScyWDBSkpDCeiO9xWIrh9E1Li1NS358S3v+0v5j+T0=; b=RJqgzQNdJO+GFRyyQhqd/uWmeuEwIcuji3l9uUrcKzT9FxKmHydjnJXbcKGg0+l9kT ytUJ8e8YJiCeDyo6KGsOAqMVTh9Q8m4F1vKeIKSypf8wWAM5nOB1nSNw89aQ3uXcfS4C rxwDDOp7OCF+ssUkh63U7SuElmgY71nuGqnXpdVi0jFqZOY+hWrvwc68TPaAODUY2LeQ naxqFEuKdohYbMPlcVtt7d4idfIuSOC0ht+/5jyCLzxyEiwo5KvS2Nwa+2Nadht81DdB OmGoPzDx9BmiT+0z6uz44LnqsBQXCAPoSuUT2++poWe/OTEZ2b4r7km4xSaIcuZE1oAg o5Uw== X-Gm-Message-State: AOUpUlF6JoSCDq60SKEZdCwglyD5aKmvBkkaqiPBbwOIl/0/YR8v+g48 pUaWFwAXHwfE6ILU5DqL4df4iQ== X-Received: by 2002:a62:3601:: with SMTP id d1-v6mr16421214pfa.41.1532415450265; Mon, 23 Jul 2018 23:57:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z19-v6sm2465351pgi.33.2018.07.23.23.57.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:29 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: 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 v12 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Tue, 24 Jul 2018 15:57:46 +0900 Message-Id: <20180724065759.19186-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 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 Reviewed-by: Philipp Rudo 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 Tue Jul 24 06:57:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142690 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918196ljj; Mon, 23 Jul 2018 23:57:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeMzB9sHQaXnOcDe9SFfRfkoeiL7KdLSs5oWEhQBx1TppDU6baNI/aN0m5EvASKcwj1OCoS X-Received: by 2002:a65:64d7:: with SMTP id t23-v6mr15405846pgv.207.1532415463341; Mon, 23 Jul 2018 23:57:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415463; cv=none; d=google.com; s=arc-20160816; b=snk5UkNlW42HHTby7tvwSLntO+H/zTUyiTuPbkyNFHOIJ9lHqg/Ltg2v0rYPJ5AkGr 3oozdLDenRZu5gNQszcLYRjhwQiutkgvdYUIkI/l0U63qzi4XOyDgj+lbDNQ0/f49Edf fP7r9RsFrroGApE5O1TnBR/7Nh0kXNS9F0b/9KrVq9vrxAaD7gg8xdLbIroBfyhIyeLk YQosetTfChccYne7j3TwUZyWuxx7MCVU7WjpvS+dbfvDeHd29hijkufpgSC2CWb3P2Iq 1aYOF/iH+fxQTfyFKlczqXVZDC+ZUYH+qVBpf77+AHmExyfrMxhoprsJ5/7L0MO7OZur 9nxg== 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=n4HcoP+WTvAeoAsFm19FwxSxHpLoU20/JAibgnpWWF0=; b=qNMJPe8I3gd7Nv/NqZnxuxcVbP4aLazBAQbxzAycsUD+JeihluNerGNVWZ0WD6EnbL uiMqTDuZUvD4IUUqcGJoa4XyPNBZpWrIHPFB8LMKPjVDnOrt6xSFOnQhiLn5r/haL+lW V/E1BYnZPwXreosVMjzIQsCwFmh5duRfUvByXGjNLu7iFsqJ4cZB5ZRr/u5M4VnAcUcj rNvoOfLDax1VHtPZep49s4FQhGpZ+FyredPQ+qIVMl0h0dKqY16//WNdccAn33fTH2iS ghr4gO/4fLdwsIh6oSYo2tzU17+ZO0l6btuQtlhGuE/y6yWlvjq33cwoA0Eh0Q9CAidC zrXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wryl1us2; 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 v32-v6si10142418plb.273.2018.07.23.23.57.43; Mon, 23 Jul 2018 23:57: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=Wryl1us2; 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 S2388470AbeGXICh (ORCPT + 31 others); Tue, 24 Jul 2018 04:02:37 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:44379 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGXICh (ORCPT ); Tue, 24 Jul 2018 04:02:37 -0400 Received: by mail-pl0-f67.google.com with SMTP id m16-v6so1323877pls.11 for ; Mon, 23 Jul 2018 23:57:39 -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=n4HcoP+WTvAeoAsFm19FwxSxHpLoU20/JAibgnpWWF0=; b=Wryl1us2gO6DrmNmMtIVXaVWLAGWibT0SJZxo5ygw9YEyEXizgGaX/hljMl37iwOxL O9fQo9u5/A8HDRUbRPleQc50NZxrE901vGIOJT7LTwof20aDo1HBDWb+BAxzXeT/e2YC +iwCjOzQGUwiEKvwOzW1iq4kUFe9chIOTcI9I= 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=n4HcoP+WTvAeoAsFm19FwxSxHpLoU20/JAibgnpWWF0=; b=OgDmMIytfKuDeggDLVHgLIKpUO/iEiHE+2dsK02SnK8aUQStTTADW/KfxwjUejpVGD /ag3t4ewDXBjplZvndvn+dURh7BdtIWdKAyLC+2d4wWP0stYTJ7KhZhGbtaLcpqvnmJS 5lboR8GiFbal9RTJutHX72CwZL1IfsfnMD6wzcSz+cSH7hWRVxU3RdBMY7BP+/1jyM8w VzobS3AsfM5TSGlUy+L+fl27MEOoKGKDo4YCyHEvXgtv0Cg+31Wv1rwcZ5+bti4IF976 MfeqQNNFKlnJuRoUvhLaR6/S2KeHmC0iR0yj5MFhcjnWhntzgYSnwvm5cS2Q3xMVRFXt Pbxg== X-Gm-Message-State: AOUpUlGZMlur/jZdq/bv33QTfoeywKgYN6Gik7y/PBX6ZVnoco1X3XWR T3WGl5wsKbbe4N3WTYbZLYpKEg== X-Received: by 2002:a17:902:e3:: with SMTP id a90-v6mr16099122pla.227.1532415459458; Mon, 23 Jul 2018 23:57:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 14-v6sm17684945pft.93.2018.07.23.23.57.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:38 -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: 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 v12 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Tue, 24 Jul 2018 15:57:47 +0900 Message-Id: <20180724065759.19186-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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(). kexec_walk_memblock() will not work for kdump in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Cc: 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 | 58 ++++++++++++++++++++- 3 files changed, 56 insertions(+), 58 deletions(-) -- 2.18.0 Acked-by: Dave Young 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..2f0691b0f8ad 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,7 +560,7 @@ 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, +static int arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(struct resource *, void *)) { if (kbuf->image->type == KEXEC_TYPE_CRASH) @@ -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 = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Tue Jul 24 06:57:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142691 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918348ljj; Mon, 23 Jul 2018 23:57:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfizz+PVeRU1Oc0S56BpCmKC4vv82KGDZYDyWL8PxbF93ELwyxtjtU62DIh6iTZucas9iEE X-Received: by 2002:a63:b95c:: with SMTP id v28-v6mr15036192pgo.162.1532415476037; Mon, 23 Jul 2018 23:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415476; cv=none; d=google.com; s=arc-20160816; b=RA5Dl8o0IvCYmSoKM/RnS5F7utjW+IxC5R+f37+KS1akhY4WnC8nZMwruqi7FuHpRb mL1BJLHS7L8zKQ3DDVub3WJKJB6JGfuvK7Sd+NmRytmc3gCuMQxtoVur2P2DVXYJaNvk R1f5JxokpVF8Rb5A9DmM+99BexeJ1Jmv/S9Xz9y7NDrfSKzPuUsmbgDYWjhdJuQZqyJ3 8TIhnTOyrP9ophAAaZEsEHuD6GMmDwZNt9Chjx4pozoAvD8SN0owZn41bs3DujjCl83Q ow1GBVtz5nHZWPtONvtw+JdSJkH2Deb7T3CNPXLLbIUOt3ShQz15wiFmzOwcpUAEy+s1 gN3A== 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=qX+9ZLjYleTqiYTR/9AsWjndzTTMAgGfRwkaazjqic0=; b=iIbwPce76d8tNlwe6xgu9nd5NOeZa9mCH6kEGpWuJEcrC1Gm3oJG3PlMaakVojf9DI XowZLXpaP7jFo6DPeUSBKIq92GkGSqlnRhF99hYFOlc2sUQB5fRBsUJFjee1pih2jFO9 u8rZUsMcfbIUq4L8pB3zM7S5BxkzJHLGHSiZTh+v7lVgB/8Xp8cIMzI9dAPwdJ/J2+mN G2101ZIVJ6NLy3k3Ruf1wPSarNVLZ4lbmqMh7fr3+aV0rNnpmUVK5GctpMhVm3kjepnN KeGxrzjW7kiWbh7ntu3NRtz/UORZUCvQYTXaqrfaEutCgNaudkmz7E9andQegko//xlh 7HEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gjx6vY7E; 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 d11-v6si7664471pla.442.2018.07.23.23.57.55; Mon, 23 Jul 2018 23:57: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=Gjx6vY7E; 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 S2388483AbeGXICu (ORCPT + 31 others); Tue, 24 Jul 2018 04:02:50 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37356 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388331AbeGXICt (ORCPT ); Tue, 24 Jul 2018 04:02:49 -0400 Received: by mail-pf1-f195.google.com with SMTP id a26-v6so623643pfo.4 for ; Mon, 23 Jul 2018 23:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qX+9ZLjYleTqiYTR/9AsWjndzTTMAgGfRwkaazjqic0=; b=Gjx6vY7EwRTKIrVY9J55sUQ34HHFlTe4FmpRadgter9yKeBuzeehOo01GQ1nzj7rQx IZZnGZQGxgEy+Nyb24xy4H0OmFFN3qMUY2CgDgPuxd6PM27plx5Ier0qF4WBMg74Y3nR 3/P+rUjJOAnix3Ymmp41EkC6E95ZGNa/i+SuY= 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=qX+9ZLjYleTqiYTR/9AsWjndzTTMAgGfRwkaazjqic0=; b=H8gOE+UDUEPkebKkDxPGu1I9PRHT355o8UB0uXpSRMxsUSqW86lgFsKWqp9+/4Z6oc QzyvR5Tr7AHl1mH9cAsJjRzCDgxVq3Uf4x2zL3omL+IhE6k+huWskgJCfVjdaVy3iKG5 8FgcZxtL8BlNK5a59ZFaHDXnFhDdZQJAnQPKMpNjRNzMGQ8HxARvaPCtfPflXyndYW/s JBXFc73noE1hQaxKZhQw9EhW7YONgS4oGNYhU2gGfoSL6YU4aN/YMYRAQEj7We+kG3f+ zWuabaYboxNWnVlbAJCQbLmXpeurejA00xOxZHkWoWffztkAAOaHBzg9qnXBDBYPZrQ/ srVw== X-Gm-Message-State: AOUpUlGuNTzzUJgxy7lur3h2VNo3F0fsz4d3J5XZSBvR+bpzZegiUSkM CHNPosDCiqt0WbI9gZNsapkIGQ== X-Received: by 2002:a63:f756:: with SMTP id f22-v6mr14890781pgk.289.1532415472243; Mon, 23 Jul 2018 23:57:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u185-v6sm16092326pfu.134.2018.07.23.23.57.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:57:51 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: 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 v12 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Tue, 24 Jul 2018 15:57:48 +0900 Message-Id: <20180724065759.19186-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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. Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- kernel/kexec_file.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.18.0 diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 2f0691b0f8ad..bb23f9280a7a 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -511,6 +511,9 @@ 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, &mstart, &mend, NULL) { From patchwork Tue Jul 24 06:57:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142692 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918447ljj; Mon, 23 Jul 2018 23:58:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdjd7dFNH5EmWEcSoPPqVS9qn+yBrrLbG2UGdvKrdTdGdfUFrGsBxWyN8qbmCPbaJ8KpVR4 X-Received: by 2002:a62:1815:: with SMTP id 21-v6mr16557588pfy.227.1532415484996; Mon, 23 Jul 2018 23:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415484; cv=none; d=google.com; s=arc-20160816; b=quTYQSlbO0BaATrM6AWYkypv4sU84UbWppnJBEx1GH7sijfCXKVPTN/7vsbflLK5YF yRj9ApwmuIBb50Sm5FCj08S7fuebyfgk2JByhQl3BtTfp2/+gI9veTxmwJVsSkSp5qRy 9RATgTDInnVa0jDicUQaLQ5qwdx6+I05bisEAziaCYnGczRIz6Da+Bsx4l9awEx0Y4j9 YntdceuA3dh74Kqh0wAEUsNvFOYfviueFBHLd2OuoM9ZCH5yujlA0FHEcx7coTPopRGR csiWU347XQ/GKASd92/HRPsTku3vTS6oHYTbNIzaverf0sr+tQdlAoUz68qb9skmxdUW krNw== 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=mQ23beFqb7IBYgI/hwlHF+9bU/vR7jK5hqVgaNZd8VejbGGhpgxjhuv7LPH1bebb/4 KXYdW6Z9dn8LEyT27dT4Zxel9rS3kyxwqZEiG6F4excxMbiqvG9KHuZkGInioP0z3Xpm aRiqFXiz2FuBZULfQSb2nlYWCEQmG3M0X/oR+YNELJtNpJZ5YU3bUDgYVNGXooKr3j9U imUIHHu8GcsRvW58gm+yLfPfdyxypek9OOmBbH1J0u7Ln1RVOKhNRE45qAgOY2InLFIq AScuBtRtbrz9KqP5TFChA/itOmP2jOl427jZQa38vw3CXHK8zx+muNtjIPbkExvYYTG9 ojHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BK5+jtRP; 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 n1-v6si9501955plp.166.2018.07.23.23.58.04; Mon, 23 Jul 2018 23:58: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=BK5+jtRP; 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 S2388496AbeGXIC7 (ORCPT + 31 others); Tue, 24 Jul 2018 04:02:59 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40153 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388331AbeGXIC7 (ORCPT ); Tue, 24 Jul 2018 04:02:59 -0400 Received: by mail-pf1-f193.google.com with SMTP id e13-v6so621830pff.7 for ; Mon, 23 Jul 2018 23:58: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=fLowSY6mJuob0j2AasYwzHifbnb4+IvdIDuIYU6ROck=; b=BK5+jtRPvI4T2uWUEa4FbqGVKf2792r0k4n+769No4hC++DANnRliJes3gizzPJwz4 XjaqadmeavGNPkIDA5kKCeBd7DXiKCqV75rtFjOaPqX1QZ+/kpw7a6W+noWagVqOaIMA MOH7RjRGCSSqcKJwDZld3rmTYpq4o1GNfz+4Y= 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=kjtNRlRGe8otx/JvJbSkOjeaCQZVVS4jo9T1+ThgCvDK+LAHimT4A2EqPd5Z6f9I3b XsLhZGP73CRN491WPcXdyZx+ILtBK+Dj6JgEDV/TFuFWHDeqsCDUsFDyh04hAHeIZWWH FSz5T1FvoaMgBWIIvKWlWwXCQbthoUamkbbDRRtS1qlsxPrW8+sMYnTznT3HhxiAU2pi vy7wSwrTDS6KqnNu8hdboLOUfAWB+BZTR+GDAr6HtAjrZtMerWSXw3ALcJhVFZfvRvh3 zO930S4blhv3k+B664cuI6GuZY/BVq7RWtwYnxR1xJW9aZt47FZ3zKJzip9aiZGhSqYh hT8Q== X-Gm-Message-State: AOUpUlESX8uEAlFWR0RmLgV20Scs5HlQJoFTLIqn/csUB1LgoYJpcOOE 3UZ6COJdgQWooescpNMgRwX+lA== X-Received: by 2002:aa7:84c2:: with SMTP id x2-v6mr16328237pfn.220.1532415481321; Mon, 23 Jul 2018 23:58:01 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a20-v6sm13998713pfi.124.2018.07.23.23.58.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58: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: 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 v12 06/16] of/fdt: add helper functions for handling properties Date: Tue, 24 Jul 2018 15:57:49 +0900 Message-Id: <20180724065759.19186-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 Tue Jul 24 06:57:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142693 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918521ljj; Mon, 23 Jul 2018 23:58:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcwIcciZt5XltKEhzeDb+TkrdmRIE37weuyp0B1fXxrxjLghpSGLOJMQaS5qk/HUIsRBcz6 X-Received: by 2002:a65:5144:: with SMTP id g4-v6mr15086517pgq.21.1532415492814; Mon, 23 Jul 2018 23:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415492; cv=none; d=google.com; s=arc-20160816; b=BZ/wvy6eQlqvRS5vxsmkg5CM4iTP76lrwV9O/S/wOQ2XwD+f2WAiaVdvIdct3niFOq h435ZQsbgxvoUVpHkFzdLgCH9/HSsV7Y8mn8576/E5wnePZ5nsfV153A3M2CApd+pBLu 5GCKExsaRTDBpwkOLFh7+ApPHglV3KrdizgtFYg4ezYagtVC67dwWWfxUAvAQIpvfJ3I is5XQ6SXgiwVckLzfPESMYj4yHe16Y+n6frsmjGN6lv1ciYGJHH6na7WQb4103amj5OU l1NpP9h1tv4CrN0bzMjgoxQa4MAtHBbffsQ4X7m9bxcI0nyfBTp5FGkplZlRifHyxLbf 2IPQ== 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=DJjHu5wUadBrG9GmHHRW2qfmFXB5dwMaSsS0AhzgDGllWWc+/ORdrw0vFOjZ6QCxqo oXtQX5Dd0aWc3f6IMGBt0/fER4dknvkSFn0uSj/OXJ+9NxhJBiqf9SKK96YqeqQDp4fR 3a9YsCRNiXKuxJnRE2CbKNweDeYYfEFvbKAN71RPsptG6iP5QjK3eHSXT9Xx5X7QOdpW kjY9WGKrm92JiQL6WBsIBzC8qY3kREcZVNRg/NIw3GUxdzP3KjX80yrmDPmZM664STWc s6ICOoPEjFespdbiTyK6bIq5n+w/ee4i0i9nE8M6gOw5l3j6W91P0xltdVGPpwT+/VbL 2uLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="C/yqdvKW"; 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 n1-v6si9501955plp.166.2018.07.23.23.58.12; Mon, 23 Jul 2018 23:58: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="C/yqdvKW"; 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 S2388508AbeGXIDI (ORCPT + 31 others); Tue, 24 Jul 2018 04:03:08 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37507 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388331AbeGXIDH (ORCPT ); Tue, 24 Jul 2018 04:03:07 -0400 Received: by mail-pg1-f194.google.com with SMTP id n7-v6so2190799pgq.4 for ; Mon, 23 Jul 2018 23:58: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=iV83B8R4RN0S46KhJwI/DPsWmsVjF3gQZbNOLfrDO2o=; b=C/yqdvKWveGmKVzfCDCnCkBq5NcFX9WA1yra9YOhCwvn9CfIM1fEOdK1zcjJ0ekASY p6+Ufuwksx9ALn1kqyOHJMbrBNTCPm74x4jxrdTj7H+j5bNDIqHPqIEoCE1nYZexUTJ9 EtEADpmliTcPzQlEruISMb1H0icOglJoQlEj8= 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=t6IjARzmx5DIOiUl0vv+lnldaFchPilwGSmnH8Q+L80GLhQWbEDK+Yl8ZlQsKXk0w5 zitoE9pdx6kIaJvvS3OqahZInasmyf6Mn/gUCIeDFpWJu0LGh0EeM2u4IPc3znmCVsEw uQFaeLTZDfcyWZebds0IvbEodm27Xyh09+WXxozl9ae2/+AlpBZsodPk5RTPFOzQx8U4 +jOvE3tmt+APF+h4vLK+kWITbJFqcFp3IQFLmJUP+Cc1Ru3tk4a4hfGb2VkQtOQQQdv7 U20WhkdN2WBQ2VQlIPFLgH1rhD1yhMRlbC38/09jIM9CKbeYYIzFnfl/EexyV5twv31b h+pQ== X-Gm-Message-State: AOUpUlEF81cOFd3W+Xl/E1BCJwhV07aUDAU3NSE/bihOGDOl36L1yKf6 rXxfGR6sn9JGvtJVyUjaQRwv4g== X-Received: by 2002:a62:e00a:: with SMTP id f10-v6mr16513182pfh.208.1532415489663; Mon, 23 Jul 2018 23:58:09 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t14-v6sm11418710pgu.0.2018.07.23.23.58.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58: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: 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 v12 07/16] arm64: add image head flag definitions Date: Tue, 24 Jul 2018 15:57:50 +0900 Message-Id: <20180724065759.19186-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 Tue Jul 24 06:57:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142694 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918641ljj; Mon, 23 Jul 2018 23:58:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfJh0cQ9cxBiR0Glyu3xSbXdyJIyC0FJ2tMHHckgDbKghx0p1VW2JqzuYm0HadhO1/9zRBn X-Received: by 2002:a65:4587:: with SMTP id o7-v6mr15426870pgq.317.1532415503330; Mon, 23 Jul 2018 23:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415503; cv=none; d=google.com; s=arc-20160816; b=iL3MmZRISjEorJqIcAPyByICsHQ5YkQ0tPWpCl0RLb7tIKj/XKjSjVGcUCNRke4n4w Mg41dydpN0E7cNxvZBQROKekyMKS1xxAWsucypQ2cbPe8D88x4ILJs3ZYU5sXIwF4UNJ pkF5M5sQeAyi5lkIcwDgtAv/xKWoo4PgKroBX/y5+hGog4EZsQPO3iYdcPGto6JCUFt/ WzbwMHf75IH4WdrDAJj4zCmovZmAN3iq/dl/y5tN4dnlmnE3FA74H5xoCagKDerBIgTi i5VeuTG4b4CNTBVte25ubmcE4xWBDUnSmuQjH/hxyZ4yNSk9RN/ZzZv/5BgtSVXBL0gq dOig== 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=nfJyW0wISi7pFTcHvVTkSJuPOwx1kzaBCIM51YbouDshaIOKvtKIHwCZ3h8qVsKr7j 5iJaz16/ycfa4R5o2No/sGkeBIdt9HPQFpEhEdSXPfPVpVp+LBIqXBFb4DTcSiZ/Z0YH 452eJ7RFcYrwzruNqCFxZpRa+OL4m4CG6DgJHkOVMAy1+hZgM/QdcdkjhjEEAnSkrNW9 EJrVAKEmROI7h17RWlI2vTeTs5WdVuHS2stisoVGMr+FcU45y+on2wAaeci+9xIc13Tq RItv6ire8qS2wJag3f3N6I2xB20i3Axho0FDIzmIbvVbCcjzBI6KLlJpVhtAdE9aS2CS sIRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZCAvraV; 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 g15-v6si9613427plo.23.2018.07.23.23.58.23; Mon, 23 Jul 2018 23:58:23 -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=IZCAvraV; 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 S2388516AbeGXIDR (ORCPT + 31 others); Tue, 24 Jul 2018 04:03:17 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40795 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388331AbeGXIDQ (ORCPT ); Tue, 24 Jul 2018 04:03:16 -0400 Received: by mail-pg1-f193.google.com with SMTP id x5-v6so2190311pgp.7 for ; Mon, 23 Jul 2018 23:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4lNt0s5QqmaPUumDTmDh9tuGftffvBV/eRp5isuKW8Y=; b=IZCAvraVKXBMSrt+LprXRPa8TzsWBujFGzK9iGYEfcaNi9ch0BExwJB2bhWlPjxxw5 0RxjkbJ0RyPgwkU8AJzqEAb+Wilqoedt05oJtDRJAm0xODSkBfBlNNDzb6/9iqf2Xea6 ccl7Lfh3ELIhGGhvF4npOmcNsTPh8kJ81C+HI= 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=ojozzl+Ewb2OFLUktYjdhfBQY+IIjJaej3IwEcON8J2LTL9wiOQ9jil6l1mC7rLlrU qA8/2m7LlWHaRl05mqu8P5pjsJiYlFXGSX+sM4T+14RGPzao+y3fSNYl9AJ03EfxZl8W 6E+3QUwZOfBD4fw3keX+9zFZ6bF9iIa4IOLuUROJxuHOWL5IZ5/R618+MRrNtoIMAVxb CyriCod5LeYhRWu0vpwrxRcAjIgcRLHEfxxVnkBeG+kNafnxv9QPVqDSp6Qn2gXIFS8g AZ2SvlMeMT9b2heMNBw5WpYhY9d7tVaPOpYRn0fsdsMZdWpk1SCGe9zn+GbPFX56Gy96 Ifcg== X-Gm-Message-State: AOUpUlGZzyIrpgvoUwDmu6PxNgPXh91E5fn2++XfwTtN4Jki7isvfNyv Sh7uhgA2wWW43gGxHHs539GuNw== X-Received: by 2002:a62:c0a:: with SMTP id u10-v6mr16375735pfi.43.1532415498607; Mon, 23 Jul 2018 23:58:18 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r19-v6sm15966732pgo.68.2018.07.23.23.58.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:18 -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: 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 v12 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Tue, 24 Jul 2018 15:57:51 +0900 Message-Id: <20180724065759.19186-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 Tue Jul 24 06:57:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142695 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918717ljj; Mon, 23 Jul 2018 23:58:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcc1g0PoXR1vtDCOVGDI0Gyn0YcJcs/1K+sr0Cgpccf2XbGhQfROhFh+8TZ5DRL37o6FSBN X-Received: by 2002:a63:b349:: with SMTP id x9-v6mr15068546pgt.337.1532415509196; Mon, 23 Jul 2018 23:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415509; cv=none; d=google.com; s=arc-20160816; b=bBR3HqqIKD+1re5XLpPY/9OvFob0C1bs0t/yen8v1s3wAhzJ1qksNJ71e8LztdFEtB /Y3agepbtk0kbmXMOGe3vxL+XkPV+m3K2oNXfRzqwU2HvmlKoK9TVW9e26F2cvBMoYr6 Vh4fbGcVNlaAm+YLdy50Fk201Bxl6fDQSYe7WboOvz3mc3kTdd2m2hS1rF6K8YrVaRmU UPzjPM8TOLpYagzqoHgo21o1vsJLmdqrEPiBI6sLuG6DyEs5fULMml0iwRp0Qsvq49hg 1pzoGYcdNrKT4HmgbvZcihRzmgLQljsYWW/rTYnSe2eeHLzFvkaULCZbGnPqiJ+NmU2j 7c0w== 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=KpsdpYdK4Ysd+TV+/RS+nNDg3tlVVRvIVtSFn8+W9VY=; b=hc687RVChPZ0wBjk/jNkomAyj86ju6p9R+Lam/eNZ7PiJcS3zIJSMnWSSAG02e/PYJ aMYAUm4VVa0vA3vz1rlw0krYhYsUbtx0q39mVbd7h6AXJCJUDUQAizLIpjyV8oqb9iVu +46N76GvBTJey6i0nteQQKBa3HOC5W28yUTuUf360MfhI+nXaZ+hcWmHPAHfkBVLCXR/ vhDS/ongpIR/qLtC71YcnlTFpHATxBaFIB+bd4iccndVqvd+On67fKrictBY1SE5vmUJ Rlr9tgC/nLW/OP3hP0k8+P+Z/BXxK1Wnc+pLSxKCQizcW8mWTvDDJbJY6obywLu1n1JB 7DJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C0Z5Isxh; 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 x1-v6si11215656pgx.60.2018.07.23.23.58.28; Mon, 23 Jul 2018 23:58: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=C0Z5Isxh; 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 S2388527AbeGXIDY (ORCPT + 31 others); Tue, 24 Jul 2018 04:03:24 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46715 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388301AbeGXIDY (ORCPT ); Tue, 24 Jul 2018 04:03:24 -0400 Received: by mail-pg1-f193.google.com with SMTP id p23-v6so2176044pgv.13 for ; Mon, 23 Jul 2018 23:58: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=KpsdpYdK4Ysd+TV+/RS+nNDg3tlVVRvIVtSFn8+W9VY=; b=C0Z5IsxhlehoOj3yXB1+CXNGBevv2cwHj7x6AgVewoFkRY3kQ0tSRABz0nl9YCj1A7 dbVu0OsP4aLNOXDh73SV6cSH77OT6r6hfArvF0igrHylRoHNskMCSZJexXxcwKkK5zAa kiZ1NzeNxhvYrXTjlM3PLcerbGCrlh2W7MtMw= 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=KpsdpYdK4Ysd+TV+/RS+nNDg3tlVVRvIVtSFn8+W9VY=; b=V5i/4V7g8NdZJxfID8lmdKarPE38qwnY/u7P11AHiDKODUxDRy3wn3nwjCzgH3R2cU J3gHY/GRaCtMKOPsG6pyLvzaqUhm2G/Yhc/XQmsqyGXn3EeIIFnVayFIxZQxXDIgEY2J CcMWwpzG/LS14vn6ER+Hwp0SIsvbsjZWU6fMkBwizqfjjHUxVXX+9LQ93DYI1pQkzPjN hPAZLmmxGQhaZ14/XOVhRaY3DwHtikHe+9EVYiDv9dJAqmbeoakcLa6FMc8iQpcISs8D LAzV1yf+gNU0K6AdqEcztGK2NFsTanOG8WOoy/ltZ3mLgMTxNzso9R+LHSTNVK9PE+YK M85Q== X-Gm-Message-State: AOUpUlHeLOQVp86uE1Hlg6OKp3Q0/pS47YiS2CriYqn3rd2cptZ/upuo 66GMM6RciJ5BLOABjmCQGS6sSw== X-Received: by 2002:a62:aa02:: with SMTP id e2-v6mr16287521pff.211.1532415506173; Mon, 23 Jul 2018 23:58:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u1-v6sm21299425pgk.25.2018.07.23.23.58.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58: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: 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 v12 09/16] arm64: enable KEXEC_FILE config Date: Tue, 24 Jul 2018 15:57:52 +0900 Message-Id: <20180724065759.19186-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 42c090cf0292..a9a3a5583c8b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -835,6 +835,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 0025f8691046..06281e1ad7ed 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -48,8 +48,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..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 Tue Jul 24 06:57:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142696 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918831ljj; Mon, 23 Jul 2018 23:58:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfO0TPMzjIJQEWPfFAEJu3V6hLYCLW3Vub47ttlj4kdPa9E16/A9b/WwWZIx9IALWMFR3UR X-Received: by 2002:a62:a018:: with SMTP id r24-v6mr16506495pfe.144.1532415517226; Mon, 23 Jul 2018 23:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415517; cv=none; d=google.com; s=arc-20160816; b=FAvCoE8g7h3f1QkLT/LiW/RUFt3oT4wQTnOyE0kwCMhp/X8P+Tqli1DnCkgbqFExct vacOmo0zxWcJu/d6IyFWcIPoZ2MN4ajphbrUorwqYzGhr1dw94uWT9f86D5cutZ08xsG ewHnsZnGUtVR0sNhLzkFkTn9KCWCjgMLxfV2z0BsvMdq8JQo5cutwiX3SfnYDP+vBWkZ ikyIWiANObK8mO98kd/ud84UacgjlI+C8rw8A450cLeEgGVAILd7UeNtOdrHJJrtLSqp phL7en7C9ptXReNNFbPJgq4zBySn5hLPJkqJ33ssEh05I20nITvoLb4YT/cnFa3GdHOn uJRA== 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=Mz81qDhWmAiSNYpZZsOHlS2lDMScwrCRyCwmff186zc=; b=vK4ujTysow2D6ZJ2Y3nirzVQM7PnAQeXmkJ/Ur/VUdNjuBeZ4SNLgGISK6VcnCaMsO kV9HoKrpipLswIHI7FCRi6qP1TMOI068tiC9JTI8RR4hPyMT48onPY5+Eiizdw9Mpb0f Xyo4JF2mRC/gk++JLsyEQX/dm++cns94ESHZk2fEZCiFcnK/VIha2MoXSxARnfniAOOE /2Cl350YPf281wT82bwMaybpSDol7r5AtUjZt995/q/vFW20CAAly7SCKFzAbP69LmZo vdIKmZLDUaz6j+lrz+DaJ6nPI9ebMI+GUduR1K3Ms1Bg6d5y/4nRbi3aqu2ZYWAFCET4 7xtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RQ5UcAXc; 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 u12-v6si4887461pgh.261.2018.07.23.23.58.36; Mon, 23 Jul 2018 23:58: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=RQ5UcAXc; 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 S2388534AbeGXIDc (ORCPT + 31 others); Tue, 24 Jul 2018 04:03:32 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:42865 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388264AbeGXIDc (ORCPT ); Tue, 24 Jul 2018 04:03:32 -0400 Received: by mail-pl0-f67.google.com with SMTP id z7-v6so1325545plo.9 for ; Mon, 23 Jul 2018 23:58: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=Mz81qDhWmAiSNYpZZsOHlS2lDMScwrCRyCwmff186zc=; b=RQ5UcAXcbSjT7kEJqmhN965LpvOYV0Z3cRcGDGFFYVgWqyJibRLBHN7P/dzcX8Lig8 H6hdnIASudmJfZSMpKKwT7IMQfPIIZKbiQXoPMPBaJbnMIB/Q7+L5wJHC+4dNRP9hiOT 5KdDsi1ozfgrdztYwNUOZhOBlVcoBZcLDA/cA= 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=Mz81qDhWmAiSNYpZZsOHlS2lDMScwrCRyCwmff186zc=; b=uLm+u/Y6vL+43ckNquNYvmwOrjUZEjXyWsUwsXGMcurVuN5qCDmbDJsMaVl/mSsI+8 O8IEbzoGXFamcmWRKJj0Rgw+9B2x0Psibztz8c/q2sjlqLlFG9m5/QE3AhRdnHTOy6AH RoD65gJjW9NCzgjagILa0+a95Gm+1RzovwZXORnsOisJaV+59iK9sg28JkkG0aERc9E4 C7FYJxx5IDELopKxTNBwLGqiKmIfFFQpjXFmBkD9vVtfoWeq4L/uemcDgOSiTRhaXP8t mNoHcOPVBnwPcSlDYuP3cDmskqwHRlHJhscGc7EmlvPYtmXxJzweg3kd8iOK7vHXwE+N coYQ== X-Gm-Message-State: AOUpUlEg1xKdIWHfkS9vvQx6fEaH/XuFCY2JbFuBfyxHdchReU6hfbmq YZMNef0Kv0vcllkAHMJ30fKQTA== X-Received: by 2002:a17:902:7482:: with SMTP id h2-v6mr16071369pll.185.1532415513949; Mon, 23 Jul 2018 23:58:33 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 75-v6sm18663643pfr.115.2018.07.23.23.58.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58: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: 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 v12 10/16] arm64: kexec_file: load initrd and device-tree Date: Tue, 24 Jul 2018 15:57:53 +0900 Message-Id: <20180724065759.19186-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 | 182 +++++++++++++++++++++++++ 2 files changed, 199 insertions(+) -- 2.18.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..026f7e408f0c 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_buf; + 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..b28fbb0659c9 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,194 @@ * 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 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("linux,initrd-start", sizeof(u64)); + buf_size += fdt_prop_len("linux,initrd-end", sizeof(u64)); + } + + if (cmdline) + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len("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, "bootargs", cmdline); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, "bootargs"); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(buf, nodeoffset, "linux,initrd-start", + initrd_load_addr); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_setprop_u64(buf, nodeoffset, "linux,initrd-end", + initrd_load_addr + initrd_len); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, "linux,initrd-start"); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_delprop(buf, nodeoffset, "linux,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 Tue Jul 24 06:57:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142697 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6918936ljj; Mon, 23 Jul 2018 23:58:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeAdtTwmey+V3TMi3j7FyZMifdBd/gGauCJN8n2e9+AX4rKlJwR0bMWlQKuoAP2ai62UfIO X-Received: by 2002:a62:930c:: with SMTP id b12-v6mr16354656pfe.193.1532415525799; Mon, 23 Jul 2018 23:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415525; cv=none; d=google.com; s=arc-20160816; b=eGLPIOZj+4cCZsHG9Og4RJj8xRg1rVhSp4Z3raktOIf60fLdVtQOv4B5YvfkcQjsKQ e9uZVVm/OEIQxEzD1m/FQSItOrm4ofTcOpJQFW+Fo1tZJs+raFkL+QtrSX/bLW+GmLVZ 4Ni4YPCwc7wfhZnqihJA/SK1Fy2H418ngzGWgq3PtxpR85sQohJNQs3VjSUhutZyw6Vb +uPxrvNvkUSh/tcCoFR87PgX3AnSHOqi3qSDfHTXVfCfMCZR+DVF2oijLAGZj469MZxA huhyKpB/i5JB8MtKaeUvtmijzmxCehqOPpN7WfUQ5Z1NYfwXLbXk8Na1jTk/604oHe/9 re5w== 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=5WKpaAKKCjtuCon1SB1pm/aYftkpZ2mbIZYdxG7foEs=; b=SD/3MWAAWISzSEi3x3GLSDp3IP0G7mL6f4vB7QKe0xp3llTcxYEoJkPCnzQDUAYBgc wlEgrgOkN9JIHr9CFhIZti8Oa77+PtYeSJQqaurT5nN+mP3OdK7uDt99Xenfcbq9bVsz gDnjjML64TVW6zgQtu9Yx275DsmvZgfeQuqLLaRaxoDT/T5xpfph0Wk0bjVOEc1ne4e5 EWUO4KJmSOz+5aoskz0vceqKkhXQmUoFH8uQuh7w0+nqHzEQFL0iPPzTc6U1CDAtcdW+ XQSgsylFTgIuvuUGSr2pJ35A59XzoGgGGHARv4v+qIv/N7msvznjcb8UN2RNYGXvMqi/ UvnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AarIjMD+; 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 v17-v6si11183962pfl.233.2018.07.23.23.58.45; Mon, 23 Jul 2018 23:58:45 -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=AarIjMD+; 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 S2388543AbeGXIDk (ORCPT + 31 others); Tue, 24 Jul 2018 04:03:40 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:46519 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388264AbeGXIDk (ORCPT ); Tue, 24 Jul 2018 04:03:40 -0400 Received: by mail-pl0-f65.google.com with SMTP id t17-v6so1324771ply.13 for ; Mon, 23 Jul 2018 23:58: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=5WKpaAKKCjtuCon1SB1pm/aYftkpZ2mbIZYdxG7foEs=; b=AarIjMD+eO12HJwfMB/qHMlGWfVPWzcpkxlxb2HBpAVHrlxOUUXllc7QA7gWklBJtN cdRKIPzT6tYu7cmDWbO/UFfroONpilzEZSBKwURUO9bytSNtwmB9zblcQHbkSRdHh0CZ v707AQUEDS5vsdB2Y1RhxfCF37iaA1JNXCYlo= 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=5WKpaAKKCjtuCon1SB1pm/aYftkpZ2mbIZYdxG7foEs=; b=phvJAUpHCblEaOiL/Z/ihZNe48ac/swdhcQQK67rz6+bce00rFMZrxhY6yvs78tg+J uuDUxj9jdfYnuyrAuawIeDIqr++WIgrIhw7TLSS/Nd7jmVdA+bljX6KA1mU8Zgs5aQLQ 9ens1mk6TdNdD5Nsk5ThGOmj9LUUibYmFOwN/S0Ht/ylPhkCtoSi3MkjHHKPQ+rQIcVj yAZ4sfCPi8dJhnmGjyWrNLiXh13kvoU2sk/SxvPOOMKKhbToMye3rU2UjCiMgq2T/ayt t4QkjbMQapVv1Ou3VbkZYUzZJcHn3Mqata64EjZLqqfA75NiOGQV5CdVTYHSj0xwpnWC x/vw== X-Gm-Message-State: AOUpUlEUIlwueIs1Ye+u3nFOT2QBOYUV9sdZIKge7DY1auNFYuG1T43u vd0mnpBPC+zxE4cU6NElxUnpJA== X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr15545045pln.197.1532415521548; Mon, 23 Jul 2018 23:58:41 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s16-v6sm14600661pfm.114.2018.07.23.23.58.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58: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: 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 v12 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Tue, 24 Jul 2018 15:57:54 +0900 Message-Id: <20180724065759.19186-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 026f7e408f0c..5d102a1054b3 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 06281e1ad7ed..a9cc7752f276 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -50,7 +50,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..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 b28fbb0659c9..b8297f10e2ef 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -20,6 +20,7 @@ #include const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Tue Jul 24 06:57:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142698 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6919023ljj; Mon, 23 Jul 2018 23:58:53 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfimH6Mku+APK6YhhwQJm3Hz7CnwDBf2ReVJkGbrCLoNV+aMjoZboxU8SYocXPswpfzgx0R X-Received: by 2002:a62:c505:: with SMTP id j5-v6mr16128521pfg.153.1532415532954; Mon, 23 Jul 2018 23:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415532; cv=none; d=google.com; s=arc-20160816; b=NqoY5LZ9dQui+vsHlUjifI00e/Klqw/ITiGdVxsrSydqOvp7SKuRbCOfeHqmay9yJ/ lzUieAWnBFO7aJURJmQewx54JTf1+TSsOs3TyJHVYtM6EGYYc7CzK4/v4JvFtpZf2/hM vXwsPvwx6zfXOdrv7bh1VtPBidZjnDueaeRfYs02oMXDcwPE75g2mW7KF5N+PkykUXAE R3W6dmAFwqY7vh7pdjE0RhpF1LYilylc9EyDOHI1/o9eBqiur1LhtRjZZLPFdV1PPf5K 2ZzJuL2WzFJ2NaPc9yHg2QbpgF+CUeh1zpvUmxI0IrZq5VGov63138JPegtHgR/dhakN Ohog== 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=NrZw1260Snx5buwrLrr5fcvVbV6cTmqraLcLZQTZkLs=; b=Fic4HspzQUDa1eW/NkPtjbXwzC2u6fFetHbwIFdgkH2wXfnh9ulAxQ9LLks2QWvADt XTOAKfJpj+djXSTbwWCfsrVvN8QwC/cXZ8WqPPFDvy/RNGs9CWzeIKlEGnngQFzNPLBS fY9AduyITDWl5ZcbWRz03Cg4S4L3KHot8FRJ8BmSoWiYxR+/Z7gn+bCZRvEHZ1/tX0nB Bwa7Jf8xuWtrSsIVDZT3dlWDiNj4CviGs9WdiexTzeHEaTCLT3fDutmdmJGEk7gjAw9A ALiexZXdXDkokTskmdoPjGFGkbWqz2RbaeR/erNFgZfFixSe4arjzFvPL/lfnzhdMDeS njmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y+n40Cn0; 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 q9-v6si11217921pgc.685.2018.07.23.23.58.52; Mon, 23 Jul 2018 23:58: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=Y+n40Cn0; 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 S2388552AbeGXIDs (ORCPT + 31 others); Tue, 24 Jul 2018 04:03:48 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41939 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388264AbeGXIDr (ORCPT ); Tue, 24 Jul 2018 04:03:47 -0400 Received: by mail-pf1-f196.google.com with SMTP id y10-v6so622224pfn.8 for ; Mon, 23 Jul 2018 23:58: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=NrZw1260Snx5buwrLrr5fcvVbV6cTmqraLcLZQTZkLs=; b=Y+n40Cn0PUxEfrHIT/fGbjCmcUHa0Xn47ymffC+V87QKT+cNafSRa5tfjMDNQ2XTmU gA/8rCZYwmQc5ZETtw1o6TE3N59f1pjEOgIPXXNAN0FE3ykbdYs/aEOUcV8sYm1lLANC ATiFdhuXXARVZGjQwDm63+lpg0G1s6N5FFYks= 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=NrZw1260Snx5buwrLrr5fcvVbV6cTmqraLcLZQTZkLs=; b=b9va/T64lTTfVpdJKqJyHxgXJZ0lUHfSso97iixxOGN0k3qjFHhKJHZhhVqq0YuofP yYU2vjustoppOEcHY/0zMZJ7joIgklTzuEhog/GpTipT/ibL8bqSDgtOGweBn4ZAeACB n30rM9/C1LWw7ZaA+OWPZ+haMqT5te/ujptrOkkSprkFFTjHAImo/ytQhdATgxiXiXU7 jdEKya34uPHpgP9lRO5FNU2hSxzJKhn4SilizBE609o8HoVyn3F5xH3DwoBGe3Mxhsyg YVc2uvna4Y/XC501h7FHMe/47cTQkgKVlLKVQTGMonpaBDipwtBrE8VvPwbvxhV0EKQn eZzQ== X-Gm-Message-State: AOUpUlH5hJD7z6UqrttAU5/+f6/06JTJQEYaV/ojpytVW/D0G7S/Cbg4 t6TfZ4GRqo86Ci72QfIvL/cWcQ== X-Received: by 2002:a62:6746:: with SMTP id b67-v6mr16504274pfc.243.1532415529050; Mon, 23 Jul 2018 23:58:49 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 87-v6sm22962394pfn.103.2018.07.23.23.58.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58: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: 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 v12 12/16] arm64: kexec_file: add crash dump support Date: Tue, 24 Jul 2018 15:57:55 +0900 Message-Id: <20180724065759.19186-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 --- arch/arm64/include/asm/kexec.h | 6 +- arch/arm64/kernel/machine_kexec_file.c | 113 ++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) -- 2.18.0 Reviewed-by: James Morse diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 5d102a1054b3..1b2c27026ae0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -97,8 +97,12 @@ static inline void crash_post_resume(void) {} #define ARCH_HAS_KIMAGE_ARCH struct kimage_arch { - void *dtb_buf; + 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 b8297f10e2ef..7356da5a53d5 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include const struct kexec_file_ops * const kexec_file_loaders[] = { @@ -29,6 +31,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); } @@ -38,12 +44,30 @@ 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("linux,elfcorehdr", range_size); + buf_size += fdt_prop_len("linux,usable-memory-range", + range_size); + } if (initrd_load_addr) { /* can be redundant, but trimmed at the end */ @@ -73,6 +97,23 @@ 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, "linux,elfcorehdr", + 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, + "linux,usable-memory-range", + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(buf, nodeoffset, "bootargs", cmdline); @@ -129,6 +170,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, 0, + &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, @@ -136,14 +214,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 Tue Jul 24 06:57:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142699 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6919095ljj; Mon, 23 Jul 2018 23:59:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf3N+xryOw8fjPoTJreg9W48/o5GSb0vmkb5AsXTLkABBF54A9HE7LfNzbZ5MQOsG4RDw4Y X-Received: by 2002:a63:4506:: with SMTP id s6-v6mr15553635pga.422.1532415540383; Mon, 23 Jul 2018 23:59:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415540; cv=none; d=google.com; s=arc-20160816; b=RtAlt838FU3ujguYwYNwhLFSWHGoVRQyyEILXC0plCFHzGJhhHQ3emkFk1ccl1GMIx DDuqBewMw9a3LvfYapnLdf4WpGBqFfRQnvzCqnKXn3yrTFxRmU9G8OCEiDTBwAdQ+Dsq mq2nzGzkuJ17ho19TLcKMndfzHLcnIB9Qe9ehV/zy6+6AJcJcCFFecEUD5kIdvk2hFrc rPif9ffn8OBo5OGUnE24Y64jlkohgscSRhJwBPT9K+vvMuR8qGdo8jyRvQq5KByGnX0t 2f7eiaTDIl1EMRtsqZNlCvB846j59itU8n2sh+U6QWGAVw4rKANtw/qLCnoWbSf70pGy W8Zw== 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=LYcgh+nDPKM588JQ9ma6JrqSapqsGrXqoeVmNFniv60=; b=QikzqlKo+CK2sOSr2HQoOivExTXghioXJaJY6r42tvogDtNrUdhgnmlDm0NZo72tHR FLLAh1T1h09ismrczcrnIvDpiguQaJvaYXWdrgL1Cr4rU4ef3FGXN7e/s8uoOo1WSgsd 0JQFjNHPgxS+gJCU7a9wEJM/heKjY+MKlyI8srCvFLvGtYbjKkdQn6rb9cDnUWFIj46a wqJ6O5N2r34znPkcZleq1v6Vd7H1gVWoh5gGM29PSGxupsmb4sasI2ysQKk1wT9XhaUg iYm3X67p2kDi+hJBSH4Hq1RHzxEnMgSS16+mLPpsUw3C5xz1v8vTl3lAV6LG8OSFCvAR d07w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tj1Kn5X7; 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 r65-v6si11333141pfe.298.2018.07.23.23.59.00; Mon, 23 Jul 2018 23:59:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tj1Kn5X7; 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 S2388564AbeGXIDz (ORCPT + 31 others); Tue, 24 Jul 2018 04:03:55 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34050 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388264AbeGXIDz (ORCPT ); Tue, 24 Jul 2018 04:03:55 -0400 Received: by mail-pg1-f196.google.com with SMTP id y5-v6so2199006pgv.1 for ; Mon, 23 Jul 2018 23:58:57 -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=LYcgh+nDPKM588JQ9ma6JrqSapqsGrXqoeVmNFniv60=; b=Tj1Kn5X7glWk0eA5Au7pf8DoGG35+0gnsScbyK63dcH0svlRAOtYPEmMQuiuHFyfvn qfhUyZPYaVraqD4EiL/GszUO461fcspkMlOuT125/tkekt551LIlH3/DhV9mJlo+nWtf IkBO56LtgEpsDzquzEqZqia1bu3RYc9Ef7Jl8= 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=LYcgh+nDPKM588JQ9ma6JrqSapqsGrXqoeVmNFniv60=; b=lXe+O0NVaf8G8F0ccxnhI5s/3CVHCM97cE9SjyEUXeYTPQCE7Ys830sPvE2bLlG1Uh 5UoVSD//ZfqOqre93Bm0b90iLHGG6gMIc5eX9FD/ZSkH5GaQ5XLoBRsq/4h1cAa7KoKV lTqB04WXbgKxdn1D+nGQAw6WvASHDhjZkGGpxLdt+ROC4goBdSb3Emh0R79yi3sNP6Nd j2841ODMq/0eV+ChrOq9wrGxvkcSrtTHgtDo2AumwLuxadaN8HtzMN0cuXD9iY8u2Ng+ bw+YYEaim77WLsSOygnALwrXC+4XRaSWIAs2oOH3wWTk4TX7dHbTeZScOI7CSSeb4CoI r98A== X-Gm-Message-State: AOUpUlHIIQ7tSuzCDApht3zfZTmvXB06wOyjNCIIvbcNPLnNuTWJWD0w TTgyREUMFXJPw852Y+4rhqO6rA== X-Received: by 2002:a65:6143:: with SMTP id o3-v6mr15494531pgv.52.1532415536850; Mon, 23 Jul 2018 23:58:56 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x22-v6sm503821pfh.67.2018.07.23.23.58.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:58:56 -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: 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 v12 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Tue, 24 Jul 2018 15:57:56 +0900 Message-Id: <20180724065759.19186-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 f76ea92dff91..830a5063e09d 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -205,10 +205,18 @@ 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(kimage != kexec_crash_image, - reboot_code_buffer_phys, kimage->head, kimage->start, 0); + reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->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 Tue Jul 24 06:57:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142700 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6919153ljj; Mon, 23 Jul 2018 23:59:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe1f+YjHGo5bD9J1yqh82eanWhRP8+6SlLmJHQpPrGyQuu4JvYG/q1LIbhbfAkQYFXiwTkh X-Received: by 2002:a17:902:6845:: with SMTP id f5-v6mr15716437pln.173.1532415547905; Mon, 23 Jul 2018 23:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415547; cv=none; d=google.com; s=arc-20160816; b=bQJQur20/nRgtIqFvk91irLbtaw4PgQMazFJk66MFntY3ufPs7ZmR7huLhWQUOwn+q 41wHW2oC1gO4/2Ho6xiyZoDVbNOTAx0YhQV2zvre+hQ1pSeU4sA9hacXmHS8ibJTgg0i bfmircvTBxD3+GwUDuRT8FCWehsrmty+rC8+M/NYFSoKOsFY7J0A3qBExbn1SpqxPJ8U x3JaH3zEieKxzr0RFXcFLeC58Fh3+qxIn0mr+yozOx5JfQ5uRr8eTMdLcFlH1dutdHaF z4/+h+VuZDdx+/sgnzkbgH5lfRiv9slVM7I+nGW1ibeLZW+wWHkqegerbbg2v5va6Myt +xkA== 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=uX30zb5YYJuQXTkpFZE5tX7VHma26KhMp3TIDrYewDVNml0YLo8NzW+PTnLSM/ytkj 6EGPrPH2IkGKCaCw6tN2BnVAx181+WgbBsn//RWrD0jmYfRuMV3rJHP0TzmMDvbKWC3c YgP29+etEJpeemXfQtwpnoj20wdVYBFdDyKQ/HiAgVBhoe/MjQtuTVakOHYNXCvV7sy+ Dh3IA3GhArSD9cx/Qv5J9O+M42MpQ0aik5IeNv9EsmKrCNTdDvxAH9QGoPIu0HFUld/6 fbnUa7kAvZ8DaRXjX28nitEv5AEW7mDrn4IOZz5DklZJgHr0wXM1GPWZQB3KG7SJgTae PdZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YBqxVMLi; 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 b6-v6si9511073pls.347.2018.07.23.23.59.07; Mon, 23 Jul 2018 23:59:07 -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=YBqxVMLi; 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 S2388573AbeGXIED (ORCPT + 31 others); Tue, 24 Jul 2018 04:04:03 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37603 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388264AbeGXIEC (ORCPT ); Tue, 24 Jul 2018 04:04:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id n7-v6so2192409pgq.4 for ; Mon, 23 Jul 2018 23:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H8r9Y6sXiWjrMnoHACDZ61CdzVHsVLeFpn0oOZb/59I=; b=YBqxVMLixn/XZ7QzSmXVIbTgC2hE90UJKhy++UyocFiKZo1r0isSuzudJ9uMFczRAk 33CyhfGgCIlK92u0bTUhQSMunExi5YOQUhEIe6Myke4ydsrIUkeUMIuKoNyPDP2YFTc5 pRfh70mIT9IfPcJhoFAMaH2RK39p+KF9d1whU= 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=YLNIxYI0l4OtR3rFotHg37ddYd8z8DcMotv58yUcKl5eubZKLWG8FlWU9/Ak/lkrZe VO43Iqm0Qjs+j3Xfk6oVgFTxSlfFvpbz6Kf5Q67KaTtBIuVUvxEka8a4TT4B5itoB5S4 QvsneNGw71AlrKCvoERSTq/3UgdVli8OrQeZj+npjtTPn4qiRnfmX6P+jhacvqbVn2GF ETbjX6jtHB5VvyuX8Jclj8IhvIvxlreagfQkuIx25njGIjTGPJeQYzfdSsDRTFHtCdXs +/bzPSaDKyipXZi6CgAlir7DyCaeE46WUOz6zFhv51j3c9a4e/iWfvElTjOEcOsgxxeM 8saA== X-Gm-Message-State: AOUpUlE10mlaqiVX/WTFR1Ku269UHgF3PukTVmA2xJ8JO9QLSW6Jq58W 51zt5dNENmP+0HYHUNsnPw0A8g== X-Received: by 2002:a62:1603:: with SMTP id 3-v6mr16382476pfw.245.1532415544496; Mon, 23 Jul 2018 23:59:04 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z5-v6sm9588659pfi.4.2018.07.23.23.59.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:59:03 -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: 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 v12 14/16] include: pe.h: remove message[] from mz header definition Date: Tue, 24 Jul 2018 15:57:57 +0900 Message-Id: <20180724065759.19186-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 Tue Jul 24 06:57:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142701 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6919242ljj; Mon, 23 Jul 2018 23:59:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcPih1k6mav8oKQ+HdpJhY0dRwjGkKyp0xSA7QIBKnCYhFrlw18Q1dHWxB5nRoeXSJmX/xv X-Received: by 2002:a17:902:a5:: with SMTP id a34-v6mr16096580pla.60.1532415555832; Mon, 23 Jul 2018 23:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415555; cv=none; d=google.com; s=arc-20160816; b=dygfKuAAA3rQzpOvvqwGXuygnmVHzxSk4Odd8WLCPypfsL7aVGFKLzWWNjAm0BARi5 Xmxu8P4SXeFVtOX0KK9+dnszyX/hP4GTKCJuw542HxrW/F+4ioLYrKujgZnA98yCOlmw YHli3JkbX9EryiEZNv1pet635D7UhyeZaBk4nR9GoXd6gCyHMshuJwyXnQ5oMKC3DbOT RVwsowV7EPWTulckVhhurK85zDNryCfzJHI4036KhFz3UvTN5EScDd/iG6+Rip5r86qf Xf6FsTQvnUpmK7pp3HVPTT53e73JuhUWy/RRzz21AAPW5ESMg/qujS1+7Ezgl/41B9uc o8eA== 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=pwXt6vap8yHX0ws+sEoumnHhs6bkGBBWSifGoV32A7Y=; b=VB4lWkTBi/oEifPdZvifufQc/kF22MBqwA1dEJTyYv+2bRdI00rt9rukjmTVbPhtIf H2HXMptPBbS7TBdp4/6kKbXcYlOj8DnHl6HJCOsZJzoanUwIB1/vbNNmRAKzxSl7QrO0 24LciARFllpXHlQ85kWwyOJTTDGdNlGJc6/wDkPWhW0/nlE+dBNhl9UFs540MTxaWCY2 KWZXffkWC22hZnNsJRcIFmbuT9priM9uiElAziHbaWN6H+BPdquhLB6X+WWQ1HCCPMky gWU7r/9HkOlcDz37rWiDUD9PCUPJMuVy61INoKWORbEp2wEpQ81jI7+MP1Rha69zmBG0 P3cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YqMA37RP; 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 p123-v6si9676944pfg.281.2018.07.23.23.59.15; Mon, 23 Jul 2018 23:59:15 -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=YqMA37RP; 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 S2388585AbeGXIEL (ORCPT + 31 others); Tue, 24 Jul 2018 04:04:11 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:40373 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388264AbeGXIEK (ORCPT ); Tue, 24 Jul 2018 04:04:10 -0400 Received: by mail-pl0-f67.google.com with SMTP id s17-v6so1328531plp.7 for ; Mon, 23 Jul 2018 23:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pwXt6vap8yHX0ws+sEoumnHhs6bkGBBWSifGoV32A7Y=; b=YqMA37RPrwDG7QMbekhUUHSkhSv6lFzDpMZn38BDZBonF4qxQNMpXVgwHX0+Qg4Oaf /3V2lz1+76QcGqE/OOehIRcxSCjbF29D+xDyrTkr7sDoabpzDYPx0ChmHhvLY1fX1Ugx nZr0y9zbP9jAzyB+admjVWsewji7m/SKzXCro= 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=pwXt6vap8yHX0ws+sEoumnHhs6bkGBBWSifGoV32A7Y=; b=GdCZRROwano2Wq3HRr5FL/1OFAK4LvATN6YaaI0l10PbOLo1SKXl59fRoZRcmXYojk KkKaX4p7ZFXWFbTtio5qF3xKiM/L6OosDqUzd5un+pbXw+HTBH3twOy4pUxvqZdE8Tsm fbTh7fCUC8NLIjlkPNzoZ6d5WDBN+/J/0UJ3ObItLPrjA+aOogtPk9/4FxLw2OtBMtZd IYJuRVZnuPZAFrh9v3EDwtWNPmkesPepmTRGgmgwWmEjMTbqJKbiA7WmUVDz+2xPAY71 bsRFMpiFj9nK2ROB6dV4vWNGKBPqFREiPY1HlpT7RrplkR/xz0yg855UxKxr+g6s1weS xSnw== X-Gm-Message-State: AOUpUlHqb0SSHUpwPqaiNQxXpboBvp6rUOCFQdcxbnw4aWNVHuvh9XPZ IqEDsc9p2J2V9BtJUp0bbv8k8g== X-Received: by 2002:a17:902:8486:: with SMTP id c6-v6mr15657253plo.283.1532415552316; Mon, 23 Jul 2018 23:59:12 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 21-v6sm21506976pgx.20.2018.07.23.23.59.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:59:11 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v12 15/16] arm64: kexec_file: add kernel signature verification support Date: Tue, 24 Jul 2018 15:57:58 +0900 Message-Id: <20180724065759.19186-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With this patch, kernel verification can be done without IMA security subsystem enabled. Turn on CONFIG_KEXEC_VERIFY_SIG instead. On x86, a signature is embedded into a PE file (Microsoft's format) header of binary. Since arm64's "Image" can also be seen as a PE file as far as CONFIG_EFI is enabled, we adopt this format for kernel signing. You can create a signed kernel image with: $ sbsign --key ${KEY} --cert ${CERT} Image Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/kernel/kexec_image.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+) -- 2.18.0 Reviewed-by: James Morse diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index a9a3a5583c8b..1445eb2fc833 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -844,6 +844,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 Tue Jul 24 06:57:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142702 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp6919357ljj; Mon, 23 Jul 2018 23:59:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdQsRrVOEnI9u8R1pPO8vJzWb0H3GzTB5jBhdwxuSKEcrsDKvfRuJtn9KB4v2lb6RVmh2eA X-Received: by 2002:a17:902:22:: with SMTP id 31-v6mr15973440pla.332.1532415564342; Mon, 23 Jul 2018 23:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532415564; cv=none; d=google.com; s=arc-20160816; b=SOlD9Z5TYQdaOsvgM9bwUFyDTrJkZRS8ky+KIG6fzeFeLOAeMpeDrl3Oe1bt6b9wom v6NLmHvW8Dv54ZLiMYElJiG9LE4p9dLKpdUFWuSkGnSvWfkMCQ0vUiwPittR8XSYAho2 OCBlL9Pba+2KVhQMJEy+MVuzI8BqWNX+nVEUHUW0Kj3SW1usctengNKHXos+hTvsdYTA KoMfYCrTaOEtwWmH91pLQzDntnNLf5WjmQbBbfEOfAaZcjEKCpSzptZMVaIVTZvR9R2a PuzbQ6JPVeUJ9pvV4TITQSvnN5EegzUbWmfcSsrN+BJ3mWuG8NOICLTfm66tLBbeJoGJ VVBQ== 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=DjZGq5WnpjvJN9iGuoJut9k6LjLfxTrv7tJcxElB2q4=; b=cn7lzQptoYBVhkFuNxa31tyGH555ihFfdxeN7QrvutNFO7l6CGr9nCddUjSbWKDu9Y IOk6t8pL/oAZdhpQ3ajmS+JWiYmIiYjVRvdmcgpKZAXgwyq46PNZx41qGXRptr5Uy1q1 /pt4xStFqfGvG+8CDTZgRk+fSYySByzGhEFpL5SOj1wzX4rpX62xkPNR42kyb3bG0ca6 GjN+nVAPvxrYYbPzWx+HHXkYx7Xpv6fn7YtnZ3MsHey26vufxVVNOKl9JKf9jTbg5pKU qUtFeLifvDuPaQ8MDu2ojymhNEy6mNPSxj6/j50wKj7DTQ91YBSJ+M9qUI91ay9Qi6iN rNeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LOBGvQ46; 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 l18-v6si9465021pfk.78.2018.07.23.23.59.24; Mon, 23 Jul 2018 23:59:24 -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=LOBGvQ46; 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 S2388592AbeGXIET (ORCPT + 31 others); Tue, 24 Jul 2018 04:04:19 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37639 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388264AbeGXIET (ORCPT ); Tue, 24 Jul 2018 04:04:19 -0400 Received: by mail-pg1-f194.google.com with SMTP id n7-v6so2192898pgq.4 for ; Mon, 23 Jul 2018 23:59:21 -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=DjZGq5WnpjvJN9iGuoJut9k6LjLfxTrv7tJcxElB2q4=; b=LOBGvQ46EyOi/qHw58fwmvardQ5MtYZdZsKI2bhd3NPyZ5Ngm05h1zVfpxB28HzYsy cC4OHjfFrWjqeyA6R50p272ExOYbm2fuM7josvLnYlfJCXoyHAdXS4h6od0vIP6qBJNY +HYqMAUASv9ZTXy+It/cFonObSZhmrKAg+Pqo= 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=DjZGq5WnpjvJN9iGuoJut9k6LjLfxTrv7tJcxElB2q4=; b=pdE6aXCp54pgPajzfqX9F41/H0FDXmIF5YegGs7/jr2b2wAYaK9AuEmFE8dF8lpT0K sVplZhER+oQTVTf0e5ccRRbJfZl4Lag88e+owO5lVRfvDCcfr93rXvPyVZaqNijAk5Bw +UYIZj9Nqj8rGOiSfw4iY0pnL5YEQSBXLAyV0rlDBQNGPwNV0sE/0pXrCsN+NqfEEn/A iGamXZgTXYDlsLP8bv1Ns+EQUOXN9lKYqQ+D1n28lmmRF2H0EV7uxW9N0O/f0A8JIJ9R aL9LfRWC8JMOacU/ExxzxrFUi3EI8ZAWZ4Qa+wLjV8p7VH1P7iXYe+Rm4pFQG4R6XKKz dSDw== X-Gm-Message-State: AOUpUlG5XTO+VXC0cdVP26gNhggjusa1qmHXtfSeKVSAyuopeiOFvjXC NKQc/+m5Tp52Ln8gB6WjsbwEqw== X-Received: by 2002:a63:db05:: with SMTP id e5-v6mr15062646pgg.152.1532415560822; Mon, 23 Jul 2018 23:59:20 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c6-v6sm2027520pfg.138.2018.07.23.23.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 23:59:20 -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: 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 v12 16/16] arm64: kexec_file: add kaslr support Date: Tue, 24 Jul 2018 15:57:59 +0900 Message-Id: <20180724065759.19186-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180724065759.19186-1-takahiro.akashi@linaro.org> References: <20180724065759.19186-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 | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.18.0 diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7356da5a53d5..47a4fbd0dc34 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 @@ -46,6 +47,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 */ @@ -158,6 +160,12 @@ static int setup_dtb(struct kimage *image, } } + /* add kaslr-seed */ + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop(buf, nodeoffset, "kaslr-seed", &value, sizeof(value)); + if (ret) + goto out_err; + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;