From patchwork Thu Nov 15 05:52:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151163 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6593432ljp; Wed, 14 Nov 2018 21:52:21 -0800 (PST) X-Google-Smtp-Source: AJdET5eAosUltk7aCcFIYot9EGxL6XxVD/XMDW73Zg/EP4KYIKw2Rf/RsY3p+IrS34kOdenTreJV X-Received: by 2002:a17:902:e201:: with SMTP id ce1-v6mr4976510plb.138.1542261141655; Wed, 14 Nov 2018 21:52:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261141; cv=none; d=google.com; s=arc-20160816; b=SV+wZyfjnILEHe3HXVCnS0wCYvY84eqvw3QAlVU/U1RNB9KCDmEd3Bs8ypFXNJjS84 brZSSWdXFzkJn45NvaKOPSSbOToyptOMawIOu5hZcMjBvVccKLRjW6vZ4BHpauFQi9m1 at5emHOXEQLUkYTZvazTFQV8Mpdr7+pnkIGESJQxEAS+dm6cG63WVlt54vfyvd1giJMz PNeFG0puef1Qy8gKfsIPFvzb6wIqDATQ8n93+xeiK89CgfzYWxejui47oTlIpw7JHyX3 Hc2tFU2Z0IuioYcibqFitRjUHa8UITK7e+kAx0FJSxvVvmtZUAQsNxVRhnizS6ESqWIx DZtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fqOZgrmCseBCFVCglpCnlv6Vd3lKQ1VgNlnEF5YSifw=; b=yaRr1BpbTlQTPlMbucjFzBbHzHC5oQIDLr4+ZrzTg7Qv2sSMq7BdoQpdUh09LaLvsR kg2Yyoz86jRC+HAPoyTmXYqsGQEneswOydmO8CpyEUxFE2Lfr95qMRzZ+GInvLSNFbWK yBzrWdQLUto6KMmKnKEqx/sH3mPpeylRXeGNCqwg0IREBjRO/Uqv/2Lg6H5tFdEjKyOL eRpEE3pKw1UmvsdQ4mCYbEejvG9atu2mdULUZxIEznArC8do6QPabBiupNt8bLtuBwgm SW7AR9Qc1D2nIKIchXFrPG3kmVLmae++ZjBQewtVSaEqfziUY0Eq8GsintG/BNYlxGZV JCLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L0Lh7ada; 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 o3-v6si25467979plk.360.2018.11.14.21.52.21; Wed, 14 Nov 2018 21:52:21 -0800 (PST) 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=L0Lh7ada; 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 S1728569AbeKOP6o (ORCPT + 32 others); Thu, 15 Nov 2018 10:58:44 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:45028 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728468AbeKOP6o (ORCPT ); Thu, 15 Nov 2018 10:58:44 -0500 Received: by mail-yw1-f65.google.com with SMTP id k6-v6so8235620ywa.11 for ; Wed, 14 Nov 2018 21:52:18 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=fqOZgrmCseBCFVCglpCnlv6Vd3lKQ1VgNlnEF5YSifw=; b=L0Lh7adaB4/NBz1Jq7eWIVyflBdmNbUxt4AY6CAfqdA8EIpze6HPfem5PTfs/DdIuy nO0Ux+nFEZV3r0qw6u+AayYXEQULmZ5BENYIXIPtRcyWfd4fEEbwi6jvmcgp3HiFs4E4 lmSB8Ghz4NgyoOF6cFUUXgOdAf6u3836RA+ho= 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:mime-version:content-transfer-encoding; bh=fqOZgrmCseBCFVCglpCnlv6Vd3lKQ1VgNlnEF5YSifw=; b=Q02gujAENopM4k72X3+CiBD8BMgNCi/HJ6I+L2BMX28z60lIaJOc7/DAaxdqGG6k7Q 9HDXDecA+z0Ocr8VYhHRKQZ/bGuxJEqLneCBo+hGvfwHHxMV9ch3E0aUEoila6PygiJC Zmr32u1/tNIMdP5v5xZlLh35uh6CmDD2lv9V+sy8mNT2sY/cg/Scak1iKRCiv1TYoNEQ 0E4P2ktyR5BOjhPqj+OXoEGBxNaPY074LBqBdS/JDshUZL0K8wQQxIp99Vuv6QO9H2ml XQZ2vqGY2Py+BQTOlvN4S8bgyQ59ZApYFWnmIDgWY2pjrMOTjDcXa/yTA/NpBg6sGJnn Lrtw== X-Gm-Message-State: AGRZ1gIoQ5cwV6lXCh6TMZaVc4ruSnKrh3PzKbblLOQvGL+GALyzIXrX YwQZTHjyUS0hF/+Kfu+E69DUdQ== X-Received: by 2002:a81:ad57:: with SMTP id l23-v6mr4569256ywk.260.1542261138359; Wed, 14 Nov 2018 21:52:18 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 200-v6sm7892593ywq.97.2018.11.14.21.52.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:17 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 01/16] asm-generic: add kexec_file_load system call to unistd.h Date: Thu, 15 Nov 2018 14:52:40 +0900 Message-Id: <20181115055254.2812-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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.19.0 diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 538546edbfbd..3b7196295fa6 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -738,9 +738,11 @@ __SYSCALL(__NR_statx, sys_statx) __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) #define __NR_rseq 293 __SYSCALL(__NR_rseq, sys_rseq) +#define __NR_kexec_file_load 294 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 294 +#define __NR_syscalls 295 /* * 32 bit systems traditionally used different From patchwork Thu Nov 15 05:52:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151164 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6593479ljp; Wed, 14 Nov 2018 21:52:25 -0800 (PST) X-Google-Smtp-Source: AJdET5eGIhL7naXe4TBCLflS2viOXm7Tcsv4ChlfPoXXT6IUVl0+TRd1pltKQf+RRqdv71bHMsjX X-Received: by 2002:a17:902:9692:: with SMTP id n18-v6mr4816271plp.41.1542261144980; Wed, 14 Nov 2018 21:52:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261144; cv=none; d=google.com; s=arc-20160816; b=mr/Gh/OwandKBlF/o9ejrVhGzMqF4a8+tz8Fjf695Bzr+cZ91KdgUg3dMbcdNZHMBi 8zTgtiR6DyAf0VsERyv3Iw6s9rNftPLVMRUWYq1VUYVMmK94hlUo+vPTIvJKUcPClxXB tStEYU8vK4P/CYJOnHEq4uRTDYABSv9XADmOLTgyO4N3Ofwkz9h3+9GjRqucm9Q22zUU jyf/gAAPxPGdSZsj1lEBYUq9edg68Y0qQyH35awKWch0BYW5R2lc+9BM7XQqYrJYC9ga bnOuZrPxGO/RfXs0AQYCpVIobJjakx1hdIxlZEJBzyy6fsrXxPB1QNdtd29pHMaX/XM7 fHUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h11K0AmVrf07I+hu2nU8xySmOw+R/bUvf0+LW2Q+26k=; b=Rz0FLNw+SWi+bzv/5sOS4SdhzpwtJrV6++ndyHy0JDyTE9hx17yDhYEyaDlsVxByYK hSq7afevbhZRkbw+YcPYUH2Ad0TP8P8Baps59hDFn9QGa6+LktnEuU486OmHSrNWwJvm nKUJ4/egdwrlDz/E4TiOb58OpkF5A2Yw7h3YOgl/+6qlX2PmvcDoTJa9yE7YpTPaYZGV lloJ2WTI1bacD2cyqmfu9hFz1t19+AxkgsGJode/gxwXbHwAXerhwuS3E+e/pu7xOBMN CFuCjAcfzMs/vJQQvC/7khkSU7WavJlf/OVtOIwcc8AcFWonrqGW6eaRbOkOAsS3PY2/ XyBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Byi9Ido6; 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 o3-v6si25467979plk.360.2018.11.14.21.52.24; Wed, 14 Nov 2018 21:52:24 -0800 (PST) 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=Byi9Ido6; 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 S1728639AbeKOP6s (ORCPT + 32 others); Thu, 15 Nov 2018 10:58:48 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:38094 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728468AbeKOP6s (ORCPT ); Thu, 15 Nov 2018 10:58:48 -0500 Received: by mail-yw1-f68.google.com with SMTP id i20so879669ywc.5 for ; Wed, 14 Nov 2018 21:52:22 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=h11K0AmVrf07I+hu2nU8xySmOw+R/bUvf0+LW2Q+26k=; b=Byi9Ido6WYyA6ak3oOwmTntFN6ZvPrWq+jnerI2g4TBQeE/AuJ9l5Xgc5LS+yqFM/G cLqhfQmJrhw/n4hQwHh529vaPJWOjbTfW9xLSnpUzBEETZs1YUvjjGk1aQsxuVibqHrb vk2e/tcv6SvR7BsOGP2ME0lvkO0W/eiCtsD3k= 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:mime-version:content-transfer-encoding; bh=h11K0AmVrf07I+hu2nU8xySmOw+R/bUvf0+LW2Q+26k=; b=PlE9yOaW2n49MzkfhTUO/XWWRbE3awfAh4eKlojgBhU+0uITrvP14SOK9vXVtsX7ww Afa8z4/Pfh+Z3DO17S+V31cUjXOY7gkBx7g0ZlOPcH+kYgkpI7CfayZ6pwgbJVxTvpf5 E+u0cmoWw0npWXxyX9D1JXqDuCAm36T+pZToox6JtVBo6uAPwFeYqRAOzzKoZUxwACM6 ic0UtOeN+u8Kouay3ORCfS5vmkEoYkaUtunhyb3Qg993CAVTHiusJkv5by5nIg7CLmnh AcBYy5JQvo+g6ujDBG3uXml0mEH2TGE6RmDhC3KEFeW8mbOEN+VONqsZHsHc6UsKXglf nIuw== X-Gm-Message-State: AGRZ1gLjwcZhTeMCN9hLtKaNxrKUTs8cRpUFsPCjQ01LBZPj/NSMh1Cw cwuN0hHwLifUxMhfujA9Z+ajBA== X-Received: by 2002:a81:4bc1:: with SMTP id y184mr248875ywa.365.1542261142042; Wed, 14 Nov 2018 21:52:22 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b186-v6sm9764855ywe.27.2018.11.14.21.52.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:21 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 02/16] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Thu, 15 Nov 2018 14:52:41 +0900 Message-Id: <20181115055254.2812-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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.19.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 35cf0ad29718..9ce6672f4fa3 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -76,7 +76,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 Thu Nov 15 05:52:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151165 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6593528ljp; Wed, 14 Nov 2018 21:52:29 -0800 (PST) X-Google-Smtp-Source: AJdET5e+MNvYgV1PD03gStN8EfnE8qaIExf2DJnSHBO4d4OUHYdXFjK4fx6cyZyVuTLWSziiHzqL X-Received: by 2002:a63:5f41:: with SMTP id t62mr4599559pgb.76.1542261148903; Wed, 14 Nov 2018 21:52:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261148; cv=none; d=google.com; s=arc-20160816; b=Ss1ca6kWV5a+jefjhA57tjqR6j1YJn1j+4sw9IfYCN5BtQAeZiR7uAKrg1nSHASxX/ T3ygN3ANrAAFiLvY64ek18W9aNHIDBh+XyOexAr2H65VauGNdS07dksryFy/dhZw1p9U HrjHDHyXPVrEIY7fcd8JED6w9nCaiMLeWfCXXF6H2NAfrQ28Hwvdg7L99L2pVXLhqcBF xoKko4Qu9TUS/AnHLeyUodjgEZUecILbQr8gPbwqIA9lD3pv/xBe2c2+vnHlLlOnAu9a 6Mcw1VFe6BQoCTCjK8kDERBDqwv7sTTA/h4XzcMK/j5NysXjURwXNPz/jSo0Bo1o8Jbn 0P5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eQVF/NE5LgDyDCoQh0ftmhN/0hZKHUsKcfSHpKIBIX8=; b=zfjcaeYxO34n9Tm1OVu/XN6EiwEDejRCj+y+XegdRvI6Ph3jMMNGxPeIwSZTPAupLo o5FITyERDEx5vTg2yX6RXG9+pIwFGH903IxdV79FDT7I5OjSDH+BTNB/Q35TBMAqPCkx 4pqXCrkhCFhi9Ls41VUSWSlQkPin+sgKoW6Y0s60ei1BmfthHDHJ/96DnnnHxXjdz8kx 5SDIhHkGE2LRRqg6uALDEf7nb4glScTnMjmWRr3AlS4YVLQTdk6helbShLgoDtGm1Fm5 hN5Q8b6vxRVt/AUNbYG+juT9zXbS40YJBRjOs/J3olMLx6DiE9u+SeR+7kAN312J8nv8 sYDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SWInm5I8; 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 k186si8561089pgc.576.2018.11.14.21.52.28; Wed, 14 Nov 2018 21:52:28 -0800 (PST) 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=SWInm5I8; 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 S1728681AbeKOP6w (ORCPT + 32 others); Thu, 15 Nov 2018 10:58:52 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:45819 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728645AbeKOP6v (ORCPT ); Thu, 15 Nov 2018 10:58:51 -0500 Received: by mail-yb1-f196.google.com with SMTP id 131-v6so7889194ybe.12 for ; Wed, 14 Nov 2018 21:52:26 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=eQVF/NE5LgDyDCoQh0ftmhN/0hZKHUsKcfSHpKIBIX8=; b=SWInm5I83ZSSOs6Oky+TLdEe+XVLwX+bqxuLVQQgTl88XpOcoinPwkYI+tOOOTsO7n am1IVi9JIJYDZ6Ew3fn3vMEfaOurkJV/Lq1FVbuFxPN/BqJUd1dWb5lwbD9suCMIZ42u XVhdIVsHj37uVaAxN1tR5PVJ2GURTvxxka/94= 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:mime-version:content-transfer-encoding; bh=eQVF/NE5LgDyDCoQh0ftmhN/0hZKHUsKcfSHpKIBIX8=; b=KsRkJuQD1xbpvLwj7j9yYfYMVfsmt2R4eiqoeclLSmq6XIniGLqFScgNhLTfi86I4T p/snNq+1v6omHuRBuv2wcNKT4hxqUNGitKcXEcGVoav4gmTw0QJ+jij3hb2pt9HqJ3+9 X79xgbJAWvAVrRBJcy0AKkvNN/dnFKw8QodSxk67FVvMgxd2OmwEc6f+Zo1isrK2gxam jyVHx3+STX5UXOe/rKTyNSUGutX0+DelWUQOmcnbqfqxUZgjkB4Wa3b028yjeftoBYYz VlTa01FmkdoXEGFvPWR1tccVOKMua1YcOpUhptJv0XUfgs8YTooB2vOLM/+0tgdEHx77 B4LA== X-Gm-Message-State: AGRZ1gIstYnj2v4aXqeeEt7R19HmMb2PKcyZd3UlKvZXDKhRcHkYMvYF O5EvYWAFVcEJdZmSJT+NeRKEKQ== X-Received: by 2002:a25:ae92:: with SMTP id b18-v6mr4695234ybj.286.1542261145471; Wed, 14 Nov 2018 21:52:25 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j185-v6sm7067497ywf.4.2018.11.14.21.52.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:25 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 03/16] s390, kexec_file: drop arch_kexec_mem_walk() Date: Thu, 15 Nov 2018 14:52:42 +0900 Message-Id: <20181115055254.2812-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since s390 already knows where to locate buffers, calling arch_kexec_mem_walk() has no sense. So we can just drop it as kbuf->mem indicates this while all other architectures sets it to 0 initially. This change is a preparatory work for the next patch, where all the variant memory walks, either on system resource or memblock, will be put in one common place so that it will satisfy all the architectures' need. Signed-off-by: AKASHI Takahiro Reviewed-by: Philipp Rudo Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- arch/s390/kernel/machine_kexec_file.c | 10 ---------- include/linux/kexec.h | 8 ++++++++ kernel/kexec_file.c | 4 ++++ 3 files changed, 12 insertions(+), 10 deletions(-) -- 2.19.0 diff --git a/arch/s390/kernel/machine_kexec_file.c b/arch/s390/kernel/machine_kexec_file.c index f413f57f8d20..32023b4f9dc0 100644 --- a/arch/s390/kernel/machine_kexec_file.c +++ b/arch/s390/kernel/machine_kexec_file.c @@ -134,16 +134,6 @@ int kexec_file_add_initrd(struct kimage *image, struct s390_load_data *data, return ret; } -/* - * The kernel is loaded to a fixed location. Turn off kexec_locate_mem_hole - * and provide kbuf->mem by hand. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - return 1; -} - int arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section, const Elf_Shdr *relsec, diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 49ab758f4d91..f378cb786f1b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -145,6 +145,14 @@ int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); int kexec_image_post_load_cleanup_default(struct kimage *image); +/* + * If kexec_buf.mem is set to this value, kexec_locate_mem_hole() + * will try to allocate free memory. Arch may overwrite it. + */ +#ifndef KEXEC_BUF_MEM_UNKNOWN +#define KEXEC_BUF_MEM_UNKNOWN 0 +#endif + /** * struct kexec_buf - parameters for finding a place for a buffer in memory * @image: kexec image in which memory to search. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 9ce6672f4fa3..9e6529da12ed 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -532,6 +532,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) { int ret; + /* Arch knows where to place */ + if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) + return 0; + ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; From patchwork Thu Nov 15 05:52:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151166 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6593587ljp; Wed, 14 Nov 2018 21:52:34 -0800 (PST) X-Google-Smtp-Source: AJdET5c9nXjLSUxhOPe991T8SHYXtkOXsVdL41ESVFxVt4JV/rfO8an+Z4tR/CxIaw/Ud7TnCT1R X-Received: by 2002:a63:4b60:: with SMTP id k32mr4527087pgl.186.1542261154543; Wed, 14 Nov 2018 21:52:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261154; cv=none; d=google.com; s=arc-20160816; b=BoZskWcI4yCULv6rtE8T56gYOJZTRYDK8ZdPOg3VHVx+7WsEoegWInZs2my+ffDfSx Znm3egxMgptJuDz81XQkTXOUL2/2ZDmK/+3wTbTmc7x1ECanLpw6miBlR4k1hykpT1z9 E3Bs78qbXSTi4se8d2CjuvlfUyTElgqeuc1oHsWUDkysQOeCRikAQKEeA64Rjn55gIBE GluVN8OVZlBPMQXg7RWaQYfWak9j0hn9ks2DdjpT7tkoQus0iMadGuUqAqFvogDmjU+s +v8HJS5N4bhn+nYOtR2XriAxyY+qZStySb3l0vwEvbUUsRVgZjrG9EurZexhRQkT9mUo 3j3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vuW0vIeG+fBL43JD346Yj35MDPMUrs8BFpP/g2qIAkI=; b=RdOGUHVXqoubeQbOafOU7v9uSD9EJMV+e0kqrpVsPnaDY4dWfmngJ9maE4PM4s/zRT HN86wwP3GuZSB9dS0NfFgzcpPJFVpI8NX6blMFEcXV0BxdbyF+yDqhhnCwYQxgpGtY61 pNm0Dk3qhn9mhbnxvOeB3llnc17euDrYN6qfVN13Mg8623lmnmdOh5G8+p8LvRm4dh3/ mmSJumH1z3cRcRC+n5NRzVQGPgEdupXrdfj6HEM7bcXe2wSMyEBbEEhfUO3ae8vXi+dX hihoj06JtyvN0mg5mXlv6rNnOqt08zZWbE3esJNTidipG47NEQUcx8qZ458saOLG94nz /RkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fmHs7jD2; 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 k186si8561089pgc.576.2018.11.14.21.52.34; Wed, 14 Nov 2018 21:52:34 -0800 (PST) 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=fmHs7jD2; 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 S1728734AbeKOP65 (ORCPT + 32 others); Thu, 15 Nov 2018 10:58:57 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:44249 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728645AbeKOP64 (ORCPT ); Thu, 15 Nov 2018 10:58:56 -0500 Received: by mail-yb1-f196.google.com with SMTP id p144-v6so7893621yba.11 for ; Wed, 14 Nov 2018 21:52:31 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=vuW0vIeG+fBL43JD346Yj35MDPMUrs8BFpP/g2qIAkI=; b=fmHs7jD24UHXdOuV/RkXNE33quq7FklmXfYHhzdXD54yuqcW05dBiwZbw9bjD6QJi1 04In6CXtz+DS4CTg8ukwS6Y2JN/kyYfarrl7ZKGCclurAduh8t7ooBJ2qMqIrWNyE7wp C9mfdCln8YmApMBPPd6S/bh0RyRPFLGUtIXWk= 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:mime-version:content-transfer-encoding; bh=vuW0vIeG+fBL43JD346Yj35MDPMUrs8BFpP/g2qIAkI=; b=ZYNWDFvBcUSvkx8seWVtMLm4UeR+dNwxdrn5tuE69FhqoKUdfaYsSfKL0LCapxS+S0 I3NOTj95DOpDkGibew8/zOSI1vCBdqHDAz1OLZszGAh7MhRI889GFlpzZI0ThcybP5Hx NKkqZFDOdG6+6Ung7w/c+TIFz/qfrCwmpqulUgIkil9QRHV1iUhoHTum3Q17v6NxBCeX J4kfeHtFNLI6DRkY0KHnoJJBmKrpB/erB8G6OsrluQMWRkZQSxaz7GTU396tVk23VUxf +OYmPniZPiB0zH6s5Qi053/QDHasrXnoXSVnyAU9/hT1+g9ycLMe2XU5S23CemoESk+v w9pA== X-Gm-Message-State: AGRZ1gLfPJ1RYM992TJSOhY03PQb9HeCD4IkGq85vhjRr3mHGrKC7wT0 32m1bgheR0YzHMoOTcp5NWSPsA== X-Received: by 2002:a25:b213:: with SMTP id i19-v6mr4461442ybj.414.1542261150950; Wed, 14 Nov 2018 21:52:30 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w70sm603729yww.76.2018.11.14.21.52.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:30 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , "Eric W. Biederman" Subject: [PATCH v16 04/16] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Thu, 15 Nov 2018 14:52:43 +0900 Message-Id: <20181115055254.2812-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memblock list is another source for usable system memory layout. So move powerpc's arch_kexec_walk_mem() to common code so that other memblock-based architectures, particularly arm64, can also utilise it. A moved function is now renamed to kexec_walk_memblock() and integrated into kexec_locate_mem_hole(), which will now be usable for all architectures with no need for overriding arch_kexec_walk_mem(). With this change, arch_kexec_walk_mem() need no longer be a weak function, and was now renamed to kexec_walk_resources(). Since powerpc doesn't support kdump in its kexec_file_load(), the current kexec_walk_memblock() won't work for kdump either in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 ------------------ include/linux/kexec.h | 2 - kernel/kexec_file.c | 61 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 60 deletions(-) -- 2.19.0 diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index c77e95e9b384..0d20c7ad40fa 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, return kexec_image_probe_default(image, buf, buf_len); } -/** - * arch_kexec_walk_mem - call func(data) for each unreserved memory block - * @kbuf: Context info for the search. Also passed to @func. - * @func: Function to call for each memory block. - * - * This function is used by kexec_add_buffer and kexec_locate_mem_hole - * to find unreserved memory to load kexec segments into. - * - * Return: The memory walk will stop when func returns a non-zero value - * and that value will be returned. If all free regions are visited without - * func returning non-zero, then zero will be returned. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - int ret = 0; - u64 i; - phys_addr_t mstart, mend; - struct resource res = { }; - - if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, - &mstart, &mend, NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } - - return ret; -} - /** * setup_purgatory - initialize the purgatory's global variables * @image: kexec image. diff --git a/include/linux/kexec.h b/include/linux/kexec.h index f378cb786f1b..d58d1f2fab10 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -192,8 +192,6 @@ int __weak arch_kexec_apply_relocations(struct purgatory_info *pi, const Elf_Shdr *relsec, const Elf_Shdr *symtab); -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 9e6529da12ed..d03195a8cb6e 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -499,8 +500,57 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#else +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; +} +#endif + /** - * arch_kexec_walk_mem - call func(data) on free memory regions + * kexec_walk_resources - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. * @func: Function to call for each memory region. * @@ -508,8 +558,8 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) * and that value will be returned. If all free regions are visited without * func returning non-zero, then zero will be returned. */ -int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) +static int kexec_walk_resources(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) { if (kbuf->image->type == KEXEC_TYPE_CRASH) return walk_iomem_res_desc(crashk_res.desc, @@ -536,7 +586,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf) if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) return 0; - ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback); + if (IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + ret = kexec_walk_resources(kbuf, locate_mem_hole_callback); + else + ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback); return ret == 1 ? 0 : -EADDRNOTAVAIL; } From patchwork Thu Nov 15 05:52: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: 151167 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6593635ljp; Wed, 14 Nov 2018 21:52:39 -0800 (PST) X-Google-Smtp-Source: AJdET5dnTUdBetAmRQf4S3sb+TXz0BEgDzC9HBp95ftvMzSsY2xTg5OSIwYkTtGVPmXR4RoDlVC3 X-Received: by 2002:a63:1a4b:: with SMTP id a11mr4594775pgm.254.1542261158872; Wed, 14 Nov 2018 21:52:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261158; cv=none; d=google.com; s=arc-20160816; b=UbxjT9/8ACZZhJU8xaT9fJkI6zZK2/EEs+sEn5RHvJLO3+W2ya5zV+W9IDdKt07HmG C4Roo3UgWbj84WKGni/pEIC5Q/bAUhZVTGHbflgpPyoi2BakGcxbP6mzGjeuDmH1p/tf yedcY4uyYaC5JGffozjyJYaurP2KtILZtgXE8JFfyY0lXx0Rty0MQRq/atL9FtSKHwYW P88EtGHUOhDhgfd/UY6vctVbsQWrO+crODo7yqtHR7oHwQkJIoBqC5LczICpF724GEKI ZRVr/v64Isn1vpLOIqq2WiUutIMHXPByMGlKkCGKeE1CGiMsvgfr1gbqh8OArUw8cwOT BzKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q/fq5bZ27j9TjpABnmRVQDUsaoFNf4lBmEvm436b7+U=; b=OuNqb83KTEVxOyid7nH3ybDyU4Eyb4/fvvuXVwmwCeCCMjDgUTWBMTiZoLWGOYTu3I /7Y8mhzjQZU2MXgTZcgr9ydd8l2NGBJUMeXNIbs5vFwGVkhaF307zcA6HpzhlvbX8PD1 Pvk+lWpWkcfQ9C53sdbaI7sa/JxLvBljpZQPGRKQ7+sSNPN4tP4j8EWN+svmsetMaSge XLX5X+c33UgXmUgd6z02sLli8Q113iq4Ri+tY1FA3FxDU5ZnFZBnBEkNlPjKR+CCsPzk 7mwImEyneiMam1bOQkQp3ZAFK74G6gVskraf8hsukuDH1kQMHxRRjwtAdtjBkFJPsw4S QByg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NlwwTDBl; 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 g29-v6si23340163pgb.508.2018.11.14.21.52.38; Wed, 14 Nov 2018 21:52:38 -0800 (PST) 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=NlwwTDBl; 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 S1728814AbeKOP7B (ORCPT + 32 others); Thu, 15 Nov 2018 10:59:01 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:37496 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728687AbeKOP7A (ORCPT ); Thu, 15 Nov 2018 10:59:00 -0500 Received: by mail-yb1-f193.google.com with SMTP id d18-v6so7926233yba.4 for ; Wed, 14 Nov 2018 21:52:35 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=Q/fq5bZ27j9TjpABnmRVQDUsaoFNf4lBmEvm436b7+U=; b=NlwwTDBlmA0fPIJo73KUlSBR/mJEba1O118YChkrG+s1/ZraNj0Y01Tr0TFVBwvcqE b3VP3vfW5vtlKY/Yaut01gBNk/g90XX5pObDWWY1scgLt7FWnLNwf0k/f/ZJAMsfodDT 75tdAFCP5GXJcGbY8269qap+A6eZpP3OQmtvA= 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:mime-version:content-transfer-encoding; bh=Q/fq5bZ27j9TjpABnmRVQDUsaoFNf4lBmEvm436b7+U=; b=mFVP+Jvi7sdjIJm89CcOm9khfz1Vf/eu8YuAyk57wY04Hh0l1cxqkspEGynlkkK7c6 rAmAqwGk8TIZbYlUa6fYl4HK8qdCUrpDjGRxZC8sn/OlH8C7W8nToWgk+ITHXO0FGTTP HVdcW5e8UAMPMbgCD+hY4HueZO0Ky1zsrXCpVq2mz0y4n9bpdybw4YZqxscVYHaNHmOs IAzIknkSvLCfGy+Jlj01SjkLmHNQ/YnbKXv5PvMm6xVQCpAEmxC16jj3EwwY6ZskEvQl 1yXSX8zbKQfwi3T8I4A2pxhTKk41r1slmslJQa24Wjv8QhIRibJHzLcteU6ZnwXQMAUb aSow== X-Gm-Message-State: AGRZ1gLddAJEDjee/Cvde8wxt6sfL0AK5g26Be/5l9coo556zpFZWw3l p5Azi619SsK1wRx39sZNrN56GA== X-Received: by 2002:a25:5983:: with SMTP id n125-v6mr4130285ybb.209.1542261154572; Wed, 14 Nov 2018 21:52:34 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 207-v6sm7416843ywo.87.2018.11.14.21.52.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:33 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 05/16] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Thu, 15 Nov 2018 14:52:44 +0900 Message-Id: <20181115055254.2812-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In kdump case, there exists only one dedicated memblock region as usable memory (crashk_res). With this patch, kexec_walk_memblock() runs a given callback function on this region. Cosmetic change: 0 to MEMBLOCK_NONE at for_each_free_mem_range*() Signed-off-by: AKASHI Takahiro Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- kernel/kexec_file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- 2.19.0 diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index d03195a8cb6e..f1d0e00a3971 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -515,8 +515,11 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, phys_addr_t mstart, mend; struct resource res = { }; + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, MEMBLOCK_NONE, &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the @@ -530,8 +533,8 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, break; } } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { + for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, + &mstart, &mend, NULL) { /* * In memblock, end points to the first byte after the * range while in kexec, end points to the last byte From patchwork Thu Nov 15 05:52: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: 151169 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6593721ljp; Wed, 14 Nov 2018 21:52:46 -0800 (PST) X-Google-Smtp-Source: AJdET5dI8ynDHbj8207qRrxXJx7iNjRtZBqKMH3r2y2LqZnwmeJktRi7Lg4AYIEsLAwDNZfrv2EI X-Received: by 2002:a63:c42:: with SMTP id 2mr4578387pgm.372.1542261166194; Wed, 14 Nov 2018 21:52:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261166; cv=none; d=google.com; s=arc-20160816; b=jdyQH8uZoI87cMSgFR9Becc14pSUC2ki1qOFYv/Kkr3jkA9rmbqtH3WWltepJrvcpO gHtAPEDDY8L6ZrM/OoOE0BBsD39BGsA4j+pFbsXdj8pVnW/X9I1RakfqLf9yfP44ngi2 nP864ypkuNMI9QF4QVxGNYH/LO+OxuMAkGCaUXjrkBoL5+WcrKnOwU7U9oVcwY27K21F OLt1atxKR943HPmsxG9tSg527uTtZZd54aU3uA1Gp4QrrJxlr0GlfJNUhcwzsRFzcrQi YsyEzYkEND3ggOm44xqxj1lX8rIjzZDPgkYsIpQKNaXiOZ8gHgvTCGKED1hooj7iqYBS ngpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BhVPs0/6RkCK6rd2OYDrSNPF0bSzTb9H/aaLYLX1Jv0=; b=DB8mgbMt8jndugKLvMgUu38EJQtjxrcTG/xfkUaW1drbg+IMh07he6Yy5U5kuv4q5j dJ0Sei41wDUc7umUVtuXxC6427B5wRKh+QGQHzGClegAK7UlA2nYGoOjXxRLraJOGczp SdYtvV95N3WS18eUb5FV51RDj+2j82A/t3Uhb3OqFF+3dHoMQpM+o+kTx9p/kNqCtMe5 dUgBULFVApA3JfAePQxzHHvJYi5fbWkXZURQ5G0Kr9OXIt+oQv+WthQCwYJh0GTl19Ys 8Zv9DiUU7qt+fGHIFke/nsL084yK5myw30LF3G9F51I6mXgdBkBlx7kj705WwOvqfUJq /02A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WxwDcLSF; 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 i198si12115424pfe.289.2018.11.14.21.52.45; Wed, 14 Nov 2018 21:52:46 -0800 (PST) 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=WxwDcLSF; 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 S1728884AbeKOP7I (ORCPT + 32 others); Thu, 15 Nov 2018 10:59:08 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:32989 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727045AbeKOP7H (ORCPT ); Thu, 15 Nov 2018 10:59:07 -0500 Received: by mail-yb1-f196.google.com with SMTP id i78-v6so7939967ybg.0 for ; Wed, 14 Nov 2018 21:52:42 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=BhVPs0/6RkCK6rd2OYDrSNPF0bSzTb9H/aaLYLX1Jv0=; b=WxwDcLSFuqY21hY7SAVmE9m6wvTPTpkujhMeYjGRCOsM8vBVn7VNbQhMOv/QDzYTtl F+Bwmu9H+GHc6kw9TrduFZrE2xvJSovmSS6M5wRhMgARpNzJ63q4ktuq2QT2RCVJfa9b q/RXBcooI4IvUtNJAV0WNKl7o9lo4kDsyCQSE= 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:mime-version:content-transfer-encoding; bh=BhVPs0/6RkCK6rd2OYDrSNPF0bSzTb9H/aaLYLX1Jv0=; b=S6+egHTAbeZ/m57rdjzkS/7ILdUAFrSJvdQf0C8s1L1VuzJZhTGLHzgEjE0xWn4iMi 7mh4Aru1t4b3f9Zq+Sr2QEMPHiTf5VeIetAjuC68gN4UxF+XNOiRDx3n3izbRw5wBise cY9dEl6OI28g/GpDU+iiKCQalwTImqZvJZzsyIA2JgMxTQosVc+gQZzocGI0G7imtcEQ vXK3qbsnNtYrebDs1Z82uMUC6ok9weFvjGAelHYMZUitSFN9fBGs5pvtCW8b31VPOYEz nSNk871yEhCYJj/G00KaYJ5mfjeo8q7JFoNh7NM7e3EFhLYOXzNIAVyKbUi5pnDe2S7T pssA== X-Gm-Message-State: AGRZ1gJnUicqGnn7x3rK9T0iLjlz5guRmLTLyfuEE0iE8g5BDAiQwwij HnaaFvYKAPGUp3FsITX/Civ9dg== X-Received: by 2002:a25:cf04:: with SMTP id f4-v6mr4496008ybg.261.1542261161782; Wed, 14 Nov 2018 21:52:41 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 1-v6sm6680791ywm.3.2018.11.14.21.52.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:52:41 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 07/16] arm64: add image head flag definitions Date: Thu, 15 Nov 2018 14:52:46 +0900 Message-Id: <20181115055254.2812-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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/image.h | 59 ++++++++++++++++++++++++++++++++++ arch/arm64/kernel/head.S | 3 +- arch/arm64/kernel/image.h | 21 +++++++----- 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 arch/arm64/include/asm/image.h -- 2.19.0 diff --git a/arch/arm64/include/asm/image.h b/arch/arm64/include/asm/image.h new file mode 100644 index 000000000000..e2c27a2278e9 --- /dev/null +++ b/arch/arm64/include/asm/image.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_IMAGE_H +#define __ASM_IMAGE_H + +#define ARM64_IMAGE_MAGIC "ARM\x64" + +#define ARM64_IMAGE_FLAG_BE_SHIFT 0 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT (ARM64_IMAGE_FLAG_BE_SHIFT + 1) +#define ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT \ + (ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT + 2) +#define ARM64_IMAGE_FLAG_BE_MASK 0x1 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_MASK 0x3 +#define ARM64_IMAGE_FLAG_PHYS_BASE_MASK 0x1 + +#define ARM64_IMAGE_FLAG_LE 0 +#define ARM64_IMAGE_FLAG_BE 1 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_4K 1 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_16K 2 +#define ARM64_IMAGE_FLAG_PAGE_SIZE_64K 3 +#define ARM64_IMAGE_FLAG_PHYS_BASE 1 + +#ifndef __ASSEMBLY__ + +#define arm64_image_flag_field(flags, field) \ + (((flags) >> field##_SHIFT) & field##_MASK) + +/* + * struct arm64_image_header - arm64 kernel image header + * See Documentation/arm64/booting.txt for details + * + * @code0: Executable code, or + * @mz_header alternatively used for part of MZ header + * @code1: Executable code + * @text_offset: Image load offset + * @image_size: Effective Image size + * @flags: kernel flags + * @reserved: reserved + * @magic: Magic number + * @reserved5: reserved, or + * @pe_header: alternatively used for PE COFF offset + */ + +struct arm64_image_header { + __le32 code0; + __le32 code1; + __le64 text_offset; + __le64 image_size; + __le64 flags; + __le64 res2; + __le64 res3; + __le64 res4; + __le32 magic; + __le32 res5; +}; + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_IMAGE_H */ diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 4471f570a295..4d0b78c95c34 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -91,7 +92,7 @@ _head: .quad 0 // reserved .quad 0 // reserved .quad 0 // reserved - .ascii "ARM\x64" // Magic number + .ascii ARM64_IMAGE_MAGIC // Magic number #ifdef CONFIG_EFI .long pe_header - _head // Offset to the PE header. diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h index a820ed07fb80..d843f9cbcd92 100644 --- a/arch/arm64/kernel/image.h +++ b/arch/arm64/kernel/image.h @@ -15,13 +15,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef __ASM_IMAGE_H -#define __ASM_IMAGE_H +#ifndef __ARM64_KERNEL_IMAGE_H +#define __ARM64_KERNEL_IMAGE_H #ifndef LINKER_SCRIPT #error This file should only be included in vmlinux.lds.S #endif +#include + /* * There aren't any ELF relocations we can use to endian-swap values known only * at link time (e.g. the subtraction of two symbol addresses), so we must get @@ -47,19 +49,22 @@ sym##_lo32 = DATA_LE32((data) & 0xffffffff); \ sym##_hi32 = DATA_LE32((data) >> 32) +#define __HEAD_FLAG(field) (__HEAD_FLAG_##field << \ + ARM64_IMAGE_FLAG_##field##_SHIFT) + #ifdef CONFIG_CPU_BIG_ENDIAN -#define __HEAD_FLAG_BE 1 +#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_BE #else -#define __HEAD_FLAG_BE 0 +#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_LE #endif #define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2) #define __HEAD_FLAG_PHYS_BASE 1 -#define __HEAD_FLAGS ((__HEAD_FLAG_BE << 0) | \ - (__HEAD_FLAG_PAGE_SIZE << 1) | \ - (__HEAD_FLAG_PHYS_BASE << 3)) +#define __HEAD_FLAGS (__HEAD_FLAG(BE) | \ + __HEAD_FLAG(PAGE_SIZE) | \ + __HEAD_FLAG(PHYS_BASE)) /* * These will output as part of the Image header, which should be little-endian @@ -119,4 +124,4 @@ __efistub_screen_info = KALLSYMS_HIDE(screen_info); #endif -#endif /* __ASM_IMAGE_H */ +#endif /* __ARM64_KERNEL_IMAGE_H */ From patchwork Thu Nov 15 05:52: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: 151170 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594072ljp; Wed, 14 Nov 2018 21:53:16 -0800 (PST) X-Google-Smtp-Source: AJdET5f+2PkiPGdZ/4X+t2BlHBDsmnPkKHh53nMja9WljL4KRokAAMV1CZ3rZQ/9uU6WY3x4JL/h X-Received: by 2002:a17:902:7896:: with SMTP id q22mr4726229pll.280.1542261196620; Wed, 14 Nov 2018 21:53:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261196; cv=none; d=google.com; s=arc-20160816; b=Az+adSqvYhAD4ySxieQpvSSVLI+IT8tuX/Ai+3kmuFHkJY02x9PRLttBLOKtqH5sYc QeDDCUZhx6cVHS+TvE8geLnL7/2lkOdtjjp0PnDjxPQ/X4jpU/r7ii1MlpeM5ovroPlK bJ4OfkQ7I0pqU4iKVUDUxtPmB3GZVWgb68vg2qzBNeSWUjjaTDMHm1jKXOvjnDsGgVLk 39oD2eP6row6A9/eF02Y07JNQmr2ez5cd7GAtSpDBzD7un34gBnYdVYinCqB5G5npwc5 jKIxOxiGmXpY/CtMi8LvM0VgMSqAcTD/ogp2SEhqi1t8lK79gwT/xlKqKZPUKxvLUcId r4vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o5y8l0NsFtoWbp90IzL9nHnwXBQanitGUE7PDY2nFw0=; b=dWGmoLWTDlnQOBOD6sz2uIrdQFwAdGbSiFnPR8kUb+ymqo+9Q8LUdHd/D50YloTXOg jGhYu0oc1Hf4yXFzK5OQkjtHhlz2WhvMGXZlb2oRP6QWRqAaR2CJL/xdij+lpyM3HyB+ o7EVo5h9xBOoma0b0+ezPxCzT78hAFyZf9EWu9MRGGTMkX0UMMiOq5FEATpPGDjHS6z+ qmbqLePKfRE6NGKkpl/j4grCHKHVlQ3e3Z0/lWaLq0cMJA1ocrJGdUPpbnTAIznS8E9G 072zFmyaQs67H04L/qdpEoWN+cOMfTwXfZFRZHGMRq6XsuHQHqC+DN1ddOzJ4uBrlf1U obSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EtBHn+kv; 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 p5si6607505pga.352.2018.11.14.21.53.16; Wed, 14 Nov 2018 21:53:16 -0800 (PST) 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=EtBHn+kv; 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 S1728913AbeKOP7j (ORCPT + 32 others); Thu, 15 Nov 2018 10:59:39 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:34949 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeKOP7j (ORCPT ); Thu, 15 Nov 2018 10:59:39 -0500 Received: by mail-yw1-f68.google.com with SMTP id h32so2180615ywk.2 for ; Wed, 14 Nov 2018 21:53:13 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=o5y8l0NsFtoWbp90IzL9nHnwXBQanitGUE7PDY2nFw0=; b=EtBHn+kvNnc+4EN2r0hbJOtGY9b+zYbzmZmiED+K8NRA7cYk1XfWnhksshiqQhgAEN ix8GpkWl+fDniCZKDfw1vzsSg0b78KRVJcHl2pWwVi1/5LbchSUTp73Er1LUijszQhf5 102zObBAKbKK1ewHXbJJ6C5kj4FiqqC/04haw= 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:mime-version:content-transfer-encoding; bh=o5y8l0NsFtoWbp90IzL9nHnwXBQanitGUE7PDY2nFw0=; b=hQlhwyOP9lZq3AWibCnvkoz2kF0PeoS1Km9mI6a43uBbTjSe4nrL9dMdlc5kFTlFJE fPVs18DgSzGwCYhVk084542pkbavkZEaW9VI6lriGeZyBryjf6dwy769OlXz05SzCKK2 E+7ErVA7AYXb+Kq0630DDnqetQQPyn8JBlWUwaM3iW3mPa2FTzvpw/5B+SGpZpvrr9ry ePqGWuqJNdoaRxEtx9vMz8a+v9jjiXqU4YgC0h0tdsSyxEGeiyK5DoLaAUMcOKkVR7hY ZkbofM531rfHv3bt3im/syfPVV+cVidac/0JtYj68DSLhba2INlkBboyqvA51SUeXmMZ qrlA== X-Gm-Message-State: AGRZ1gLl8Dja0K+XvoqO/m+zZurskkTIkVdjdgHh2iaF9OXCVAUFP+4r S2pv/F0dT0hJSQXVIp+2LXDytw== X-Received: by 2002:a81:5089:: with SMTP id e131mr1242482ywb.392.1542261193064; Wed, 14 Nov 2018 21:53:13 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 207-v6sm7417310ywo.87.2018.11.14.21.53.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:12 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 08/16] arm64: cpufeature: add MMFR0 helper functions Date: Thu, 15 Nov 2018 14:52:47 +0900 Message-Id: <20181115055254.2812-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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.19.0 diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 7e2ec64aa414..ef118d819fe8 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 Thu Nov 15 05:52: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: 151171 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594131ljp; Wed, 14 Nov 2018 21:53:20 -0800 (PST) X-Google-Smtp-Source: AJdET5cuVTODJ702RUS2aE4+bGsPnmstaIdsx58qywKhJ8OfM1Jc9nrmFTWU8LxLvXP+l1Ckt/B/ X-Received: by 2002:a63:42c1:: with SMTP id p184mr4545838pga.202.1542261200444; Wed, 14 Nov 2018 21:53:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261200; cv=none; d=google.com; s=arc-20160816; b=iCykfWh+WULgtARBdWDhmyVjuqVcNyqthXPITI+dc8MQhVhizpRhRNwl+rluBwIeat 4gYNH7k50ThD+MjBGVspUkA/vwCb01qy/yvPJGl5B4Gld01m289JTCoyuHgrB6N1PlEY bDHSEFPZxwSg3gkh3e/8jG0uFvUw6AmRSaMQ/G6k+sNuQpny3UPquzhGlJhUwyWM+INe EDScgDDe+IheQcJnjt/GcCCM+vwnW/X5lcZZ1LlBJMemtZF/EmTkoFeaEVhLNHDfKogM N8NwAX88jyaCYCVw6GO3rr7wJZQlkDHmmwD161GauSzGAz5oroxuo2fb+ekXLd371FMP UTaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v/2g1t2ZiuSybJx6NO3mxBVk7FXFeZVpACxhmjpzZl4=; b=lbx+ZOek5NuOk2A77acfzXxSC71X6cijiAqkatblx1pe0P8MthVYrDa44paCI/5Vhp 5+8jABKO2nytjs4CvlpxyAa8j7afJ+NI0OOx8lbvejQhhWa1NgTOKESGTJUjVZqPuCvs vXY6habMar7ZL1U8osfGCLC2wShjenjaT3XHVikhoqU2eA6DiJ6/vuL1enmvUdVH9roL Qmt6bDviGBEtslfV53Rx5omwjbII5NzKFCntm2B7xMBk8Ju+WWb9rJRmu+MpSSNPgvy2 wSpbeATL+lZsoeWprE9hGbvt6T/j22cI/5q3EDR3aKFd0moHCXU4vOPLlET3fh/urlnU c6/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WRM172Hv; 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 p5si6607505pga.352.2018.11.14.21.53.20; Wed, 14 Nov 2018 21:53:20 -0800 (PST) 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=WRM172Hv; 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 S1728946AbeKOP7o (ORCPT + 32 others); Thu, 15 Nov 2018 10:59:44 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:35971 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeKOP7n (ORCPT ); Thu, 15 Nov 2018 10:59:43 -0500 Received: by mail-yb1-f194.google.com with SMTP id g192-v6so7930726ybf.3 for ; Wed, 14 Nov 2018 21:53:18 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=v/2g1t2ZiuSybJx6NO3mxBVk7FXFeZVpACxhmjpzZl4=; b=WRM172Hvt4U1KKJWpGr+jhsdTHlND6n0dqnf7rnB7KR/ez937GBqOmCQCx1s21rU0p ujsZeGL5rIRXhbwM/XGgrEUm8q1RE20jG14eR764S9DPpUM1XDNxeOD3x8y8GSTl1UVZ 1rt2/niMdKhX5PvrZYLdimEpAHH7VSWUy5rNM= 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:mime-version:content-transfer-encoding; bh=v/2g1t2ZiuSybJx6NO3mxBVk7FXFeZVpACxhmjpzZl4=; b=R4EEZuY/upUA2pXLL/aNRIt4kVqkYZ1OecgrkuZapUhNJ0WfsK3m7fLNYM6eaZqIPg Lz/RA1SKCHllxWAAzBJh2LOgJB5rhOpyaQEalYlQVfuvTRsk181oBMnd5thbmb6Hzz9a RQavXdRtItvKTgSXaOY7xhzwdbmDuyCuOtbteHAVjnFiGG9EfX/gXYiNBPIl5nCXj6Vr 4ZGUDarl/Ug2riot3Ufuj6vjMc8MSnRgQ97r0TMj0FawGNUgGsvOtg+0n+UKlu3yeQxw iVsPpo6dMVOXN6M3x9dDDY1VPWVcqLTZE++1ZN1p2XwbBXlRBDqxb8RGwMXX+bTu5ODb 19GQ== X-Gm-Message-State: AGRZ1gLIjH5rkjrzJ6tNsd89edyQkDq/aFtgf05YB4HkM0Fyxj/PlISG XA/YIE0KOJAbH1SJECwzuZHBtA== X-Received: by 2002:a25:2d16:: with SMTP id t22-v6mr4345342ybt.352.1542261197591; Wed, 14 Nov 2018 21:53:17 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r5-v6sm8102379ywr.80.2018.11.14.21.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:17 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 09/16] arm64: enable KEXEC_FILE config Date: Thu, 15 Nov 2018 14:52:48 +0900 Message-Id: <20181115055254.2812-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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.19.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 787d7850e064..93dc4d36d6db 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -858,6 +858,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 4c8b13bede80..030a39bff117 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -49,8 +49,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..c38a8048ed00 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; From patchwork Thu Nov 15 05:52: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: 151172 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594183ljp; Wed, 14 Nov 2018 21:53:24 -0800 (PST) X-Google-Smtp-Source: AJdET5eCC82I1LhabjN/Ylcq7LQkRBs++giE4oei/EI9DddmxsoZctRq3rHBhvGRGJmTuSwzXNgR X-Received: by 2002:a63:2643:: with SMTP id m64mr4489944pgm.35.1542261204377; Wed, 14 Nov 2018 21:53:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261204; cv=none; d=google.com; s=arc-20160816; b=ixBS1C93Q+miobmRzk3LsjUlZD6xcV8MUsnk1NnzV3ZGIJPpm/HNFWj8JbhhEssGM3 MJWJ08RMWGZtKbs8bLb+sqqGGTJlw9kg8hGtVGxuRMwvO2ztxqSYXIWdJln/x0hOAcAZ 0P51X11o5lWewKfeduq8gnU1lRHvd5Gx2IJr9DhHXyTNuCjxP6OZQdoAX+13VzdVPIZl bY5gn9+nSzMYxrDG4E+lf5frJ2j7HrqsoJlfXv5kgY+iX86ualjr54lqtvRBpPgEjvYQ /fvs4fCe1nSxX4dmaXUV8ARxhvQQhlW0AIsqzAd4XiZXeo5CMgHf7gBsrd2crG27ueiv hTXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DVw/N+4o4xfdKNT3rQ+yr/g2LmbUltluLPP7xa2j7CY=; b=mt8U9Ab8C/2b2/4J+nFcDKVIzhUcU2a1odK31NVeggN7xsykqY/PXW+NRR7QP+9Lkf XenF37N4/ooAaC772Kfw4HUgO8tR+M9MHGYxOHBYcZxExQ140mglo6KAOjKCuq+MECXG S9VWFg1vwgCyOHKKykRjPJhhhC1DumghwTreqsFlP+fZWUixVjUsL4lK8TLIFgpcyFvJ JUUDF10swtiD2PKThlxKQDIihxh9GTkZuGOTQcHWjXs8GwSxknnAAOsdiOPosRe8fVNQ ZBrqACb4BGT/ONlgpxtYk3HkAHsuVBVxE0e8Yj6c6JB8LBbPxhCU0pdKnQU6az1eFWSe 4NUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GsW9jmBC; 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 h80-v6si24610721pfj.112.2018.11.14.21.53.23; Wed, 14 Nov 2018 21:53:24 -0800 (PST) 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=GsW9jmBC; 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 S1728977AbeKOP7r (ORCPT + 32 others); Thu, 15 Nov 2018 10:59:47 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:43962 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeKOP7q (ORCPT ); Thu, 15 Nov 2018 10:59:46 -0500 Received: by mail-yb1-f196.google.com with SMTP id h187-v6so7903292ybg.10 for ; Wed, 14 Nov 2018 21:53:21 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=DVw/N+4o4xfdKNT3rQ+yr/g2LmbUltluLPP7xa2j7CY=; b=GsW9jmBCepRRuemOaWg1s/fdiX69XAbbte5iR4Y6/rfI01QRT7mbkPfb8OzkOfxK0w y/5MfoK7vDnE5RpI4HRZ9ID6g9bA1Nq0uZ9++cl0L+B8nOhsR79UAiYVRUMSsDy5qpQs XeUoRbfCBofNBT82JdJZ+vVT/FzlsAZxelXVc= 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:mime-version:content-transfer-encoding; bh=DVw/N+4o4xfdKNT3rQ+yr/g2LmbUltluLPP7xa2j7CY=; b=pTnr8F7w1GhJRAapXKSVOkwXEgPwN4DgbQqNPVS4p0gHwO4aPusOzqpcJbdAqhWHGC 0J1THFWgh2AErDI4lwDxfZG6lOrMss8V5EecM7N20pQwrSJ6x5A5kJa0KRr7/6Umnt1P UaDrLS9jdUQRUAYO0ZmBSJ+OX61S65gLMLFQJFyRfEgpo0Gp+ibOcgKVcYJ60l6ef1LO TVG8xSjiK/4UwgmmJLshRUDkzmXDefQfcEQzOEQYNSw7Nxp8vQk2aJgHLyf4+rl62F9J 6qdl0K3mJaACHF5THMHHLXJyJ/1Af0MmRfzHSdzEMVnA5Jek0IgF46IK0q3HVztKwcLi 4ATA== X-Gm-Message-State: AGRZ1gKK8mc3PQoCu/2su7t/BQqFPmhaS4FYblTre4A8oNDZIMTlTzyE DIn8hTDURa92Aku31Rm5yjolxg== X-Received: by 2002:a25:6f86:: with SMTP id k128-v6mr4430682ybc.235.1542261201112; Wed, 14 Nov 2018 21:53:21 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 207-v6sm7417441ywo.87.2018.11.14.21.53.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:20 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 10/16] arm64: kexec_file: load initrd and device-tree Date: Thu, 15 Nov 2018 14:52:49 +0900 Message-Id: <20181115055254.2812-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 | 185 +++++++++++++++++++++++++ 2 files changed, 202 insertions(+) -- 2.19.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..bbb5f505b0ba 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,23 @@ static inline void crash_prepare_suspend(void) {} static inline void crash_post_resume(void) {} #endif +#ifdef CONFIG_KEXEC_FILE +#define ARCH_HAS_KIMAGE_ARCH + +struct kimage_arch { + void *dtb; + unsigned long dtb_mem; +}; + +struct kimage; + +extern int arch_kimage_file_post_load_cleanup(struct kimage *image); +extern int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index c38a8048ed00..b433d947d486 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,197 @@ * 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 +#include + +/* relevant device tree properties */ +#define FDT_PSTR_INITRD_STA "linux,initrd-start" +#define FDT_PSTR_INITRD_END "linux,initrd-end" +#define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { NULL }; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb); + image->arch.dtb = NULL; + + return kexec_image_post_load_cleanup_default(image); +} + +static int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, void *dtb) +{ + int nodeoffset; + int ret; + + nodeoffset = fdt_path_offset(dtb, "/chosen"); + if (nodeoffset < 0) + return -EINVAL; + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop_string(dtb, nodeoffset, FDT_PSTR_BOOTARGS, + cmdline); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } else { + ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_BOOTARGS); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + return -EINVAL; + } + + /* add initrd-* */ + if (initrd_load_addr) { + ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_INITRD_STA, + initrd_load_addr); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + + ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_INITRD_END, + initrd_load_addr + initrd_len); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } else { + ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_INITRD_STA); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + return -EINVAL; + + ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_INITRD_END); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + return -EINVAL; + } + + return 0; +} + +/* + * More space needed so that we can add initrd and bootargs. + */ +#define DTB_EXTRA_SPACE 0x1000 + +static int create_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, void **dtb) +{ + void *buf; + size_t buf_size; + int ret; + + buf_size = fdt_totalsize(initial_boot_params) + + strlen(cmdline) + DTB_EXTRA_SPACE; + + for (;;) { + buf = vmalloc(buf_size); + if (!buf) + return -ENOMEM; + + /* duplicate a device tree blob */ + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) + return -EINVAL; + + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, buf); + if (ret) { + vfree(buf); + if (ret == -ENOMEM) { + /* unlikely, but just in case */ + buf_size += DTB_EXTRA_SPACE; + continue; + } else { + return ret; + } + } + + /* trim it */ + fdt_pack(buf); + *dtb = buf; + + return 0; + } +} + +int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline) +{ + 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 */ + ret = create_dtb(image, initrd_load_addr, initrd_len, cmdline, &dtb); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + dtb_len = fdt_totalsize(dtb); + 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 Thu Nov 15 05:52: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: 151173 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594243ljp; Wed, 14 Nov 2018 21:53:29 -0800 (PST) X-Google-Smtp-Source: AJdET5fqdzsnXkUzb/4yKkbwVgoIkH4Mdp2UeAr1SLwtXvnvvcmLfI7xToXuCd1L+x8syxbCKTrz X-Received: by 2002:a62:f54f:: with SMTP id n76mr5024630pfh.59.1542261208915; Wed, 14 Nov 2018 21:53:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261208; cv=none; d=google.com; s=arc-20160816; b=lMVxUvkj1zz+WlAIv2gZaM5Ro74m17/TmgJqewS2+hdJLz4A9fsPEzfSnvfKah6pCw bDzVHA1pZ0F+z/LQNNWnXYtH8xfDtR7I5rNoAoJ8+WN9InKO0mdqGk8ocdyIo4Aoy30O 4huutSqMD77958Bqv464mgH+o+AaB69EuglXSfO6lDpxeyw5w98HFjjTpLkAdEwMwlpO bx5bwtATG/dtJq+sdKqHy4MLkp7e8es3H1RFkh7PaBqYWnH5jP+ij1PQYjYuP82HqqJN h9Y/iO1mIsVmG9KUVxgfxAcYsgNGUlJMHm3HxLrg1LsM6Vvg62cRAWEqH7qQ65Zy1tOv nTAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=b/qBGuWcB3AvKhVU7KrMVZKitcb+1TETY1zXig3nkL8=; b=g62oK1tochgVN9soDR7wrXSJAWp660IUY8eJ3/HDpg+vPufW6UHAqbTm2aJ8aTVjf4 g1/kJzh2Lb7DStg3jtMXi49eYJCI/Xh9AUeuxMrMmqZ960/n3Nt/rv4TVirD5y2P7tbY 2XuEkOmI43Zx3m4ucc3KAGa7RA4ZcKBE0S+PaMsw115Db9gZMnOp7WesgD/9nDpDxI3f zIgmV0ifg8lWyAvNivsVC/x5d8v02z+pT3rv3IRry/nKxu24LecI1qyfQlybQYrVdJ0R ZVLZCPVECSMyrK0AzlYxjw90q0CxiQDj30K8qN6Z/IAYnI0oroOhplYp1WOkJFQVmoiS odjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ePmGRPD/"; 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 h80-v6si24610721pfj.112.2018.11.14.21.53.28; Wed, 14 Nov 2018 21:53:28 -0800 (PST) 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="ePmGRPD/"; 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 S1729003AbeKOP7w (ORCPT + 32 others); Thu, 15 Nov 2018 10:59:52 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:35769 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeKOP7v (ORCPT ); Thu, 15 Nov 2018 10:59:51 -0500 Received: by mail-yb1-f196.google.com with SMTP id z2-v6so7936833ybj.2 for ; Wed, 14 Nov 2018 21:53:25 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=b/qBGuWcB3AvKhVU7KrMVZKitcb+1TETY1zXig3nkL8=; b=ePmGRPD/oeb9REqt++JiB70heutg065ySKrqGdSWOo6V5eqn8wiA24QgJuenmDeyFk 1iU6Hqv7BMepvqiJQeneS65cQHkI+MvsNKWOLaIzc5Rn/YNWtV7FDNzLRHsuHFQLiB1e 534e/vv7LkINcd7EBeWsoB8UJ1v2seIiyR5ME= 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:mime-version:content-transfer-encoding; bh=b/qBGuWcB3AvKhVU7KrMVZKitcb+1TETY1zXig3nkL8=; b=MvqT6jSt6K5QIH42kQjmYQUREoSf3EAR+OcJmvvUSOvxrHMZbc21QHQ0lcBVMyTl8f 7buCb19xeLlec6GJ67W/9kNp0m0wg2CvV2BpWO5cHsLIFPLJTvsrbHpS0QDHVFe+fBK2 4ZdriMNZOX4Z3QTmq31Wq32hsl+QsW9WMuW0p8yb1SRYw+7XumH/jE9zfil+0pJyAzR7 v+s4OcpWNN64M9PyxsYaPmBbyK4OEhTUBVM60KmIJyDN4XPZa9+ChAv+XqaK38K8rERM ngAwYFI8B9SpoHXLuchtCpOIPOra4SpkY6g/t9vggtSuTkNB5kJ3i6tB5jdxkKyStaB6 KXBQ== X-Gm-Message-State: AGRZ1gL5FtDBc5Dcc9RR+ZTBXG9qcpd8V815NGG/wAzdV81scJtbvv8j HhNeQeyDebMZd/uOxLqRYl3L2A== X-Received: by 2002:a25:84c7:: with SMTP id x7-v6mr4494386ybm.230.1542261205259; Wed, 14 Nov 2018 21:53:25 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g21-v6sm7549135ywk.5.2018.11.14.21.53.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:24 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 11/16] arm64: kexec_file: allow for loading Image-format kernel Date: Thu, 15 Nov 2018 14:52:50 +0900 Message-Id: <20181115055254.2812-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 | 2 + arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/kexec_image.c | 113 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 1 + 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/kexec_image.c -- 2.19.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index bbb5f505b0ba..67e4cb75d1fd 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -101,6 +101,8 @@ struct kimage_arch { unsigned long dtb_mem; }; +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 030a39bff117..48868255f09c 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -51,7 +51,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..9f0d8b5d62d3 --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,113 @@ +// 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_IMAGE_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; + bool be_image, be_kernel; + struct kexec_buf kbuf; + unsigned long text_offset; + struct kexec_segment *kernel_segment; + int ret; + + /* + * We require a kernel with an unambiguous Image header. Per + * Documentation/booting.txt, this is the case when image_size + * is non-zero (practically speaking, since v3.17). + */ + h = (struct arm64_image_header *)kernel; + if (!h->image_size) + return ERR_PTR(-EINVAL); + + /* Check cpu features */ + flags = le64_to_cpu(h->flags); + be_image = arm64_image_flag_field(flags, ARM64_IMAGE_FLAG_BE); + be_kernel = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN); + if ((be_image != be_kernel) && !system_supports_mixed_endian()) + return ERR_PTR(-EINVAL); + + value = arm64_image_flag_field(flags, ARM64_IMAGE_FLAG_PAGE_SIZE); + if (((value == ARM64_IMAGE_FLAG_PAGE_SIZE_4K) && + !system_supports_4kb_granule()) || + ((value == ARM64_IMAGE_FLAG_PAGE_SIZE_64K) && + !system_supports_64kb_granule()) || + ((value == ARM64_IMAGE_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); + + 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 b433d947d486..7e9d5ed3e238 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -26,6 +26,7 @@ #define FDT_PSTR_BOOTARGS "bootargs" const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Thu Nov 15 05:52: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: 151174 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594340ljp; Wed, 14 Nov 2018 21:53:37 -0800 (PST) X-Google-Smtp-Source: AJdET5c3s+4Hs9+6s5LRzElLli9x6aIkSB6ZUNnbjeG/tKWrIH43YQeV9bn/Zp6+BUykXUEsEXGe X-Received: by 2002:a62:6981:: with SMTP id e123-v6mr5047058pfc.104.1542261216961; Wed, 14 Nov 2018 21:53:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261216; cv=none; d=google.com; s=arc-20160816; b=NSYgdKlPnoRZ/v7nnXLMUy6n9qJMdd64wmC5tGZsUxvIt8LpuUx8WQZnQgj232awOS cPJ7vigjMEvKiwC/2RI4L/VdEBk5fC6JnExQUu5t1zUdrnmEOB4399OBT0KRtM5j8TZh ETl+4ldOPkdY8US3dZ9SerQkyTzDsSWD7e0YnnJiTFc9+ZKBosSdVdLwZfrtvpxoGpVC /WJff/uauZ0ccV+hA/DtcM65TdY93BQZaUj+ExzFFS60N/RyDeUOjBEwcH9CbD/d0b7s oqNSiwu1PNpMphogied5UcqkDhU02BZb600ePX8QWZg6fg1BrvbAWEgqUFZ10lrzQ1We cqug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=M0hbeCh1UKPHriGwoJtqoIhFiJS4pqBvteNzMpOOqEM=; b=E4WXGaMEJQvpatYKl/iAk7kTAkX2tRO74A71oEUhQOPsvDDHwkul0ZvMB2y+ImGbR1 mmyd4ZjEJ3VabyRl3Ht9sSmf29BEVnvBeir7pjXAQ5hcL+vjSWSC6gRkuaMr0b9DZ3To J9lqr63TgJNo4YMuvnwjvQXmhasKut1tx6sATpZdjq+LEmUKhynGxPljlSPEZu5exq4k AemlhKTeRrNQWZf6gox4tVOEJNbdnNvcRAblW7QPQIUwrJAN26jQuiQtEtJV6cliWSs/ IlSOrsO3ZKR+HA04AQeW9ZVTOM/YY+gcqdOZcChK9J82tS1eqkwsMCKXLVetsFhQ9sme OFNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j2R2QQRz; 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 d3-v6si28833972plj.372.2018.11.14.21.53.36; Wed, 14 Nov 2018 21:53:36 -0800 (PST) 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=j2R2QQRz; 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 S1729046AbeKOQAA (ORCPT + 32 others); Thu, 15 Nov 2018 11:00:00 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:42372 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeKOP77 (ORCPT ); Thu, 15 Nov 2018 10:59:59 -0500 Received: by mail-yw1-f66.google.com with SMTP id x2so1844713ywc.9 for ; Wed, 14 Nov 2018 21:53:33 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=M0hbeCh1UKPHriGwoJtqoIhFiJS4pqBvteNzMpOOqEM=; b=j2R2QQRzTmCm/H2I7k4eBK4g/dz0MuUN8Tu6rMbhngctlQhlCchBaEqc//rA6ZgW5p 6LvDiN/tCVGaLrs/lHTim7I4nTw6D2cmaOYnxEiqHPdW2l21rr795UQx4wEFBdW/3Ypj Xcq/MCZFRBF3DdYdwMiY3mH9hkdcbyiqO1ve0= 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:mime-version:content-transfer-encoding; bh=M0hbeCh1UKPHriGwoJtqoIhFiJS4pqBvteNzMpOOqEM=; b=WWly00ZKDO3FVJb6aOW5CKWvhVEY2/9ssO/IvaR2/yfFcyUb5qFduLEezKOX7/J8pj P5ezW+6aEKl6OcH+cr+hZkMe7GqrqfBX6JDZD2D/RFIyo8afZFfTuenf1Zk1H887RtDf zfKfWaPmfyaWmX9u/DfIEBictqnx5econuYDJVvhywhhqcRW4t8Pv0Eo/xN1soaR2MXy WVV7CKC6aiQu94N16jjh/qNB7BsRNeY9iLSblqk7jVUlD/qSuEYNR9wOobNFgjVkBLS3 SsFcpDotKl3I5v9wLQbltCh1AAqTDBrU8yz8f8J0VBWKJGMYxPjYSQnaF1+XqHTHGXrG DwiA== X-Gm-Message-State: AGRZ1gLZGR31jX6HLQKp4AHwXfbBoMHId/DWPsbvUCpFkuZ8ErmBqmZZ G8i2LDQomNAnZmR88OgdQ9yE5w== X-Received: by 2002:a81:7897:: with SMTP id t145-v6mr4653791ywc.466.1542261212771; Wed, 14 Nov 2018 21:53:32 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s129-v6sm6769228ywc.41.2018.11.14.21.53.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:32 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , Rob Herring , Frank Rowand , devicetree@vger.kernel.org Subject: [PATCH v16 12/16] arm64: kexec_file: add crash dump support Date: Thu, 15 Nov 2018 14:52:51 +0900 Message-Id: <20181115055254.2812-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enabling crash dump (kdump) includes * prepare contents of ELF header of a core dump file, /proc/vmcore, using crash_prepare_elf64_headers(), and * add two device tree properties, "linux,usable-memory-range" and "linux,elfcorehdr", which represent respectively a memory range to be used by crash dump kernel and the header's location Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse Cc: Rob Herring Cc: Frank Rowand Cc: devicetree@vger.kernel.org --- arch/arm64/include/asm/kexec.h | 4 ++ arch/arm64/kernel/machine_kexec_file.c | 97 +++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 3 deletions(-) -- 2.19.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 67e4cb75d1fd..660705515e33 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -99,6 +99,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb; unsigned long dtb_mem; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_mem; + unsigned long elf_headers_sz; }; extern const struct kexec_file_ops kexec_image_ops; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7e9d5ed3e238..ab296b98d633 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,11 +16,15 @@ #include #include #include +#include #include #include +#include #include /* relevant device tree properties */ +#define FDT_PSTR_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PSTR_MEM_RANGE "linux,usable-memory-range" #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" @@ -35,6 +39,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); } @@ -49,6 +57,22 @@ static int setup_dtb(struct kimage *image, if (nodeoffset < 0) return -EINVAL; + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(dtb, nodeoffset, FDT_PSTR_KEXEC_ELFHDR, + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(dtb, nodeoffset, FDT_PSTR_MEM_RANGE, + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(dtb, nodeoffset, FDT_PSTR_BOOTARGS, @@ -86,7 +110,8 @@ static int setup_dtb(struct kimage *image, } /* - * More space needed so that we can add initrd and bootargs. + * More space needed so that we can add initrd, bootargs, + * userable-memory-range and elfcorehdr. */ #define DTB_EXTRA_SPACE 0x1000 @@ -132,6 +157,43 @@ static int create_dtb(struct kimage *image, } } +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + unsigned int nr_ranges; + int ret; + u64 i; + phys_addr_t start, end; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) + nr_ranges++; + + cmem = kmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL); + if (!cmem) + return -ENOMEM; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_NONE, &start, &end, NULL) { + cmem->ranges[cmem->nr_ranges].start = start; + cmem->ranges[cmem->nr_ranges].end = end - 1; + cmem->nr_ranges++; + } + + /* Exclude crashkernel region */ + ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + + if (!ret) + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -139,14 +201,43 @@ int load_other_segments(struct kimage *image, char *cmdline) { 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 Thu Nov 15 05:52: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: 151175 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594376ljp; Wed, 14 Nov 2018 21:53:40 -0800 (PST) X-Google-Smtp-Source: AJdET5dEsvLgZBR2WLd6rV7iEvHvJwbJVcM0pv21ptfO1bgxNVArmYqvGLG3eWxXp1cxAu1TsWMr X-Received: by 2002:a62:1289:: with SMTP id 9mr5127286pfs.102.1542261220173; Wed, 14 Nov 2018 21:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261220; cv=none; d=google.com; s=arc-20160816; b=oCDzqwzKDzGELkL3F/fHNdeeQ3ydD3izlx/iPHAnlxw2qVgGec1fvvGVgmEWOoeLKM 8cYtaPJmCXalhH+Qxx6G/iWWJRrgJqNdeQGXbzO2p7z+NDsR9OqOgMtwWTXZkD6N08eB KSeotR1divnQTVZoUNhDraV7XDyqajpDbpCemzyJDVdVXlp3l1JaF6yeiGK/pecQtzjf OGO+TotYkQ9f+ujwfT0FfdtijWo6fGDNnysdL4rjP14YMHwkBTY8jK9pFazc+T1LJwK4 xZEeveuR2x+gmiBqNMLYvNFrs+XOgVJe+lrng7eN/9G14VpiKvJKZAolQOWhW5TVXbvu b3Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZdHE4nfr8T5Hxvr10M0CzI0OedYEfMU03IOSvEtlq5c=; b=pYNnyOMhSWvTets7AGxecpUnqwRFZS35qSvQ9xeXOskc5ISQtOTyBJnTLnQx47pCRA QSg2ucYx+lsPsNMPcG68G4yaN11mhtH36938Jw8ZSi5cKkp1tBWU3MBE3thF1ZeMGYTc tUrAwut9CUGlmPihb6pL0YUn52cexP4K1TF4/66oHIEKGuYHxyQHpfi5w3O4QgOckzcg 1H1hUyY+51UtTb7xsaMEq9Kbri1AvWWJCpihmGsVis6pQz8A3C94MI1holg2GVk/uO9H ZXyL5zmvhpK5ndvjyUGIa+91xfOZ4tyjgKwNYSAriac3+7gjEyraNNdDNkrdxAV6sA2q FA5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CE5vd3yn; 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 d3-v6si28833972plj.372.2018.11.14.21.53.39; Wed, 14 Nov 2018 21:53:40 -0800 (PST) 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=CE5vd3yn; 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 S1729072AbeKOQAD (ORCPT + 32 others); Thu, 15 Nov 2018 11:00:03 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:43238 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeKOQAC (ORCPT ); Thu, 15 Nov 2018 11:00:02 -0500 Received: by mail-yw1-f68.google.com with SMTP id l200so2683195ywe.10 for ; Wed, 14 Nov 2018 21:53:36 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=ZdHE4nfr8T5Hxvr10M0CzI0OedYEfMU03IOSvEtlq5c=; b=CE5vd3ynonGHBkYw/svmJseji3AdkYx2PTsO7N8kj5DlWdgSooK8h+NeNDDgdH+woQ C+judgaQy+d5cOZH/xop4WnRz9+V6OO3FQT4orsCkiBFHZVpY/tBrqK5rWRHvyRIE+47 WiBnGGR2zA9bYIgBxZaZ17TJKE47FK6i5+vfc= 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:mime-version:content-transfer-encoding; bh=ZdHE4nfr8T5Hxvr10M0CzI0OedYEfMU03IOSvEtlq5c=; b=VhMysMTlsjpX8AiwBmcSH0tCS6dzOfnMg8WZ938cV5m83uyppSpmcx7Lck4JFqXmbw zRg5KaIAQuu7UrXi4H3weEOcHYdwI/M6QZ1Dq83Aasyu0m9nBh7W3WKEiAXY/2Z8G4pq bqOytR8f+p51/p2j2jWPFwE8ZIfoTQg7X4Sxke2yMdWBj+NI4W8cDRhT5XtFjbsqKPKO awc0667AlFILcdCBFsMkuUT5VjV3mD9NfF9tecuG5lQIdQ/ZwfVGYzC5QqCSTwXic9/t wVshA4GImP/rwmyzYlP/KxwU6k1nEu7hb5FbPH0w4QNDHXMo0FlKrzpFK5CNfZjfczka 9QHg== X-Gm-Message-State: AGRZ1gJv31kPRwFQzYG5H0ixkjOvbR5qU2GqnsuVcOXhA2FJ7TKUkN2e QTUTvF1+vdMX1rVxlXDdvFwGOg== X-Received: by 2002:a0d:c683:: with SMTP id i125-v6mr4713864ywd.467.1542261216503; Wed, 14 Nov 2018 21:53:36 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j65-v6sm6516907ywg.52.2018.11.14.21.53.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:36 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 13/16] arm64: kexec_file: invoke the kernel without purgatory Date: Thu, 15 Nov 2018 14:52:52 +0900 Message-Id: <20181115055254.2812-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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.19.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 922add8adb74..aa9c94113700 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -212,9 +212,17 @@ void machine_kexec(struct kimage *kimage) * uses physical addressing to relocate the new image to its final * position and transfers control to the image entry point when the * relocation is complete. + * In kexec case, kimage->start points to purgatory assuming that + * kernel entry and dtb address are embedded in purgatory by + * userspace (kexec-tools). + * In kexec_file case, the kernel starts directly without purgatory. */ - - cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, 0); + cpu_soft_restart(reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->arch.dtb_mem); +#else + 0); +#endif BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index f407e422a720..95fd94209aae 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,6 +32,7 @@ ENTRY(arm64_relocate_new_kernel) /* Setup the list loop variables. */ + mov x18, x2 /* x18 = dtb address */ mov x17, x1 /* x17 = kimage_start */ mov x16, x0 /* x16 = kimage_head */ raw_dcache_line_size x15, x0 /* x15 = dcache line size */ @@ -107,7 +108,7 @@ ENTRY(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, xzr + mov x0, x18 mov x1, xzr mov x2, xzr mov x3, xzr From patchwork Thu Nov 15 05:52: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: 151176 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594418ljp; Wed, 14 Nov 2018 21:53:43 -0800 (PST) X-Google-Smtp-Source: AJdET5cEHVeSoJHLa1r4FTxst5dNclhHSSp3zYGoQTKQtUMj4ZZvrCngakmggeLSa6lCCz/cdl24 X-Received: by 2002:a62:1e42:: with SMTP id e63-v6mr5022474pfe.149.1542261223462; Wed, 14 Nov 2018 21:53:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261223; cv=none; d=google.com; s=arc-20160816; b=SQGAFd92cLy6hSzw09gcladYPwFVWhH2+9wWYQjzDrqlfaWsbZONyGMXZMR1tOb3PS 41JVHuulUBQq9F/hajPW5n/d7MRHghDGR0OR37iJJbQrzoWy8ypqLs5imEuMdXfHSmxq EAPdM8moJjuwl6jE2DZFIEwDtBSvxzkdyL8oBanK0pJIthaueZC6bmKzXGgrEXX6kQxZ h5DiOL981JSWEl6gkWihpCuGVW88WE4kWRLVfecdtNrje0IhBL2MwQvV+zUNlVZQYUaA r+hsAGUcdGeO/3DOage6myOodnpqC5sqJOt7nMpwKsrQjshlnnoOZ2/PMXrwJ9tgqJpR oSPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IBZa+UOaDV8TYfXAr244/shDNprkQTt1AVYjh0q1zSg=; b=vQxpdJqpRvloxSI9/GX8RY3M7GOJp0f0IAhalNvNTQGM7RMUw8+rg9FBWfTtPrvtMS 6wuRFANzNaSCO4K39aGF5CzeGXVg3yT8yz+AJop9TBl2ThIqQk3uxYiUnmMpdHOItK2v J9A+nKZPBe2nKJQKsQea5mxxTkkF0jVU/+sjweVh7VqaqBobtI2hkMhxxy/MS4lNU0WP HfY741UmN2mAs6FdWu565S5hRlgRgzHZ0X4yI9gWTzGgf+e1BKO52RSgtKTZ9YXicR2z f8HW4P4RzY7yHCNuDUQK0RypFJp6Q8WrHLQyub+322rMI8vbGHV/9XGxKAlvjatVTGSr ePpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TU4314T9; 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 h32-v6si26885705pld.437.2018.11.14.21.53.43; Wed, 14 Nov 2018 21:53:43 -0800 (PST) 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=TU4314T9; 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 S1729091AbeKOQAG (ORCPT + 32 others); Thu, 15 Nov 2018 11:00:06 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:39864 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbeKOQAF (ORCPT ); Thu, 15 Nov 2018 11:00:05 -0500 Received: by mail-yb1-f193.google.com with SMTP id w17-v6so7910961ybl.6 for ; Wed, 14 Nov 2018 21:53:40 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=IBZa+UOaDV8TYfXAr244/shDNprkQTt1AVYjh0q1zSg=; b=TU4314T9M7hEQBduv68EORGU2Ufr/Wz+AI78lNORymGpWy2/cC1Q9Il6xST8BRNKnO XBz/sK7a/7eh1YRd+LSij8lEKqoaJRFxtgBuE/CX8HLhhQR6qLgEOj7YgqO/2Zccyutn jb1KqzVxInKix5eNyz8ZQgsXNjtFPbMhmeSx4= 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:mime-version:content-transfer-encoding; bh=IBZa+UOaDV8TYfXAr244/shDNprkQTt1AVYjh0q1zSg=; b=kdIuJL7v5b5NvEGWzDgln5X8M8oQmavkgR5CD1iX3BaW59d+JNogJuOCIt4R1MjXa3 WctR5u6BCvBgk6R/gtRCgNvZSly+wZd2pABnj0WHM2+zTXLPhR99RYPTGFbm5X9qlxWC 1Fyn+aW0ewKcJYJsajFqEr6c4t4/tisDGYOi3dnOvlpWwpCDDRGwRorYJROVAgAl9Avv gIYEUVruh/ddOfTDy5pKHdoqlxB5euXZap1DLf+Yjia6W3r86PWfaRoAHXVuvfflFgKR v7etPB3ixo+x83y+KeYxrl8GyAyB/EN5tcGjWkDjfGqrh8D2irjueWnSEGxKUtAjW89A 2+mA== X-Gm-Message-State: AGRZ1gKwmfgfipqZRWAtUEIt08TYZjpAu9L3TsLsG5Fu0cTDRIPWLccR 8Z557gkqWuvtruMoKRtlQAEmuQ== X-Received: by 2002:a25:20c6:: with SMTP id g189-v6mr4548113ybg.196.1542261219743; Wed, 14 Nov 2018 21:53:39 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p13-v6sm7297817ywg.12.2018.11.14.21.53.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:39 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 14/16] include: pe.h: remove message[] from mz header definition Date: Thu, 15 Nov 2018 14:52:53 +0900 Message-Id: <20181115055254.2812-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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.19.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 Thu Nov 15 05:52: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: 151177 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594457ljp; Wed, 14 Nov 2018 21:53:46 -0800 (PST) X-Google-Smtp-Source: AJdET5dmt0tpnGoodBq7ZfBHf6efD8QqQNkZm/EL9/pfJBdWTJSxJvZKB8YnhQD/xVSx/XgLBJSZ X-Received: by 2002:a63:1f4e:: with SMTP id q14mr4429269pgm.88.1542261226671; Wed, 14 Nov 2018 21:53:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261226; cv=none; d=google.com; s=arc-20160816; b=P1Oj8baaUgEkdmclq0xL8KVlFRt9B5vWVoMSYlMWRMiApL0X19AVtKe6mCrY0NpecO Y8+qBZ3FFcJq2NXftd6M+TfxoShS/4ftx5s7JVsJkIJ3B/TsKmaduRGUyMlAIhZwe5al EPvWxB7KWFl+HfQKSbCURvoKJ1cDp2B7EQ1lHFgSuN3FVmZzuo5qrsrHIzCSOd56mZC4 AWiAmUts3FhVcpvNgpxzNksYHfcBHsNdjfN6HC2rKjzSQxToRsbJOwGc6vTqnt8UZ10F 2DYD7JzAl63ioGNKx4c+69SbEfmkcDoqALu/O0BdXoSyGwoR2ngxb1WTFfjN0EcGolsS FXyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9P53Yj/xMXiy2VwbQPz0MnQUBccWU//quNYW0Ks+uWQ=; b=tLsM0GUPOsB/q4b7eSh7CkHIvyPvU/WgCLF+cMDUPCynZd1yDaPvL0aemFqllXtc6r xSHsycNrDSnFX2WWs4JCTjwYCmHM7RVFdSdpYGNEPSDk05BsMZ77Fuz0NljKeIIQSvQ0 uPYw/P7USiKB2wIC7Ndcxrfvwp77QC1qKG4fGO6Q7TszOb/Fv4d52h3hg5mgWj5X8FYZ YuzWjPLqdAu05zWuJ83bIe0iqPL0UvljsBYOdvkkmkxaiaB8KNrFxufnAYYmFtxPIDFo qrE+5zZlqAG8GG8RCdZKlu6c8j9fUi0FZqjenRvZ3Q2atXrdWv1jOjupvDks+9j/tjCy qXRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RuBj4P2K; 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 v5si12418029ply.74.2018.11.14.21.53.46; Wed, 14 Nov 2018 21:53:46 -0800 (PST) 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=RuBj4P2K; 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 S1729105AbeKOQAJ (ORCPT + 32 others); Thu, 15 Nov 2018 11:00:09 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:41302 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbeKOQAJ (ORCPT ); Thu, 15 Nov 2018 11:00:09 -0500 Received: by mail-yb1-f196.google.com with SMTP id t13-v6so7916506ybb.8 for ; Wed, 14 Nov 2018 21:53:43 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=9P53Yj/xMXiy2VwbQPz0MnQUBccWU//quNYW0Ks+uWQ=; b=RuBj4P2KtbYJ5z9USSRs+7o18nA+07+01QwFh3UtWxMpEjf1sRCmIJdKeu9F7Dxe0b U4yhq1t6E5RWWBnY3EVAbaOpN+RsBs9HGRli3CY50P6r+V5BdeUIq1m6yrvOhnrJ4Snz kVhrmv1hMMApkndiuBYd7IAa8gpBE9Wml7WoY= 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:mime-version:content-transfer-encoding; bh=9P53Yj/xMXiy2VwbQPz0MnQUBccWU//quNYW0Ks+uWQ=; b=gCKT/i6QW/vpFxAvXM8hCuxXI7OUEG5cZcmhCAVfF0N6srD5bMidj6Iqx14pbW4jFf E7jm+JPj93L0iBWa9VaRJ0uaoQas9EnR61mZv6IrisqSP24btUa8wspkcpm3Pi8RT3Uo XxX2H9fT1Ypuk+HGkQS6grYlp4tZTzmdA4jAR+4oJw2F0qKEzAuwI8Th5X2Y+7j02/4h KQJ0ndWP2ssGapBOjuG+eF2Vaq3ZfksJyNJydG89VY+1G/53GzsO8EzG9UKTlP6e3WYG KoajPEjdIM9LLRYdIiMWK9yGzizEGssc/WFP+rCmeytm5b5/92vCBDAaBlvH2zMzVRiH KWHw== X-Gm-Message-State: AGRZ1gLZSzuVMmojnfWBeut4WSzfZVcNMS+yEA2wmYort6qGDTRqTJZp 7aqF7hATpNCtERr2ybAd1/3gCw== X-Received: by 2002:a5b:40a:: with SMTP id m10-v6mr4520102ybp.21.1542261223143; Wed, 14 Nov 2018 21:53:43 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l35sm1837306ywh.48.2018.11.14.21.53.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:42 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 15/16] arm64: kexec_file: add kernel signature verification support Date: Thu, 15 Nov 2018 14:52:54 +0900 Message-Id: <20181115055254.2812-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With this patch, kernel verification can be done without IMA security subsystem enabled. Turn on CONFIG_KEXEC_VERIFY_SIG instead. On x86, a signature is embedded into a PE file (Microsoft's format) header of binary. Since arm64's "Image" can also be seen as a PE file as far as CONFIG_EFI is enabled, we adopt this format for kernel signing. You can create a signed kernel image with: $ sbsign --key ${KEY} --cert ${CERT} Image Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/kernel/kexec_image.c | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) -- 2.19.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 93dc4d36d6db..11f3e1a00588 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -867,6 +867,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 9f0d8b5d62d3..d1c6c54c22e3 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -12,7 +12,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -29,6 +31,10 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) sizeof(h->magic))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&((struct mz_hdr *)h)->magic, "MZ", 2) ? + "no" : "yes"); + return 0; } @@ -107,7 +113,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 Thu Nov 15 05:52: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: 151178 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6594509ljp; Wed, 14 Nov 2018 21:53:50 -0800 (PST) X-Google-Smtp-Source: AJdET5dyev6yFIYps1tGyD5xJHvZkBYyUD66EVU6Z73RrMa2J9l5bsfvxgqSDdAVb+6SEM/z1FDE X-Received: by 2002:a63:1157:: with SMTP id 23mr4598552pgr.245.1542261230384; Wed, 14 Nov 2018 21:53:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542261230; cv=none; d=google.com; s=arc-20160816; b=vUByet5tw5QIcwkkeFzkb6qejqoJuJHZ8wehLGl6+jFn6omXau9tDuh5mFabK5P587 TzIO1+3xGmY7LWZJn5+6YCaeDgBHTrb0CRoQB3/QvujOsOSBd/0PY+CVrgTWeuNeTjTv ULVZ3LGv16HEcvt8pazGzUXWnI5kIHt/JHfX5UBlVYxYm++PgTyE4t2rVks6tsyh6eGz +DSuNF0JEtv8jJw11K9OFwf+N54k++vVosN3bdDrE0Cd8CJTKVyHwMs6RIGcZkyLT0js Bj+gswBByVbjl5jkJnhg8T9KnudPjFQX19FYZ8Tcr5hDF5or4KY3UycUOAQs7/CmzgD7 cI6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z6fpkRKvJjJuOzp7wHTBqPrWgQFd+w1vM5L/3Tpwhps=; b=uFEA6gIIUIR4+7gKGR5zpHYJhnWhtXMUBfELyLh8/3vqXwHHnZxt401rVg+jSMzqU3 RYocn2QgL6ok4Brb/TzcIlYg/S0fIcVDcVFixP8Kzp6W3Y6THwfz+qa+dZEbSh/qRYe8 ivmcSVjn1oW7WMS1qqIfljlqySWnCZCe/XXkOG9+k562Ues7gcyjZYFFDKGLQA/xiiF6 I4R4ppfFcHyMNvZM1zAD2ZSnBXOtQK8/7V/t9j6B9PfzPoy6rxeSeefFnpNro/IDbYEn K61KHmEOi/UebmC4vGiOXIzFbB57OSgBvO048rWdU0F0QOfKEpCIELyctrmmy9Xs+Yzw qSrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NsKJ0pnb; 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 b4-v6si28158106pla.189.2018.11.14.21.53.50; Wed, 14 Nov 2018 21:53:50 -0800 (PST) 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=NsKJ0pnb; 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 S1729131AbeKOQAN (ORCPT + 32 others); Thu, 15 Nov 2018 11:00:13 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:40711 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726892AbeKOQAM (ORCPT ); Thu, 15 Nov 2018 11:00:12 -0500 Received: by mail-yw1-f68.google.com with SMTP id l66-v6so8266965ywl.7 for ; Wed, 14 Nov 2018 21:53:47 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=z6fpkRKvJjJuOzp7wHTBqPrWgQFd+w1vM5L/3Tpwhps=; b=NsKJ0pnbz1wxK7DAjNL7ynj+T731invAf4RnUN/pFf3mEkpgElVGh79yv/MP4BIjW9 oMsjLQBGyoTfTSJrQ+CIv2CP3QDoesQIUj+Wse6zWsLaY2Vx6tWHv7U0Z4oyZXlB/3vU K9LtUxww4zddwC7VpMa1XzXmlpqRwG5oiLy8k= 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:mime-version:content-transfer-encoding; bh=z6fpkRKvJjJuOzp7wHTBqPrWgQFd+w1vM5L/3Tpwhps=; b=pHS9rqhCVHLDwav8TiRJoIEJxNdzALw6MS+ssupHRQXgx6TfLNPtIam4C+H907loUk gXik9UMtBW0tqWEmS1grOx+uYnfZuT1riOsLE4Di24dx0fUGVuveT/ToZ9QaVStFKqbL 8U+KWJDEb+I9SkzqnDldV0Ie71kM6udqU1mvEcJvY+acHxegy5MDfHmYWP1E+GjVrl8k hJZF0MRLDGKnoRL/1ilHp4XKU10YFvK8IMsCSJF0jRp1mNOoWS5rdjAxV2TfIFsVIObZ oL5loTtErrWSCIAYmLaH0VRpRUL2tjWVzT/BFnORxy1uOSOfzx+0NGMC3DbgIorC44wF VY6g== X-Gm-Message-State: AGRZ1gK5+g7KFAbWHTLpAaGhJC/PB4pNETXcX5GJXC9VSXBpdshLOktQ GjbZcuKugiHDUz3CX7uBnd1Tig== X-Received: by 2002:a81:26d4:: with SMTP id m203-v6mr4471570ywm.327.1542261226677; Wed, 14 Nov 2018 21:53:46 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m123-v6sm1526751ywe.86.2018.11.14.21.53.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 21:53:46 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Cc: prudo@linux.ibm.com, ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v16 16/16] arm64: kexec_file: add kaslr support Date: Thu, 15 Nov 2018 14:52:55 +0900 Message-Id: <20181115055254.2812-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115055254.2812-1-takahiro.akashi@linaro.org> References: <20181115055254.2812-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 | 46 +++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) -- 2.19.0 diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index ab296b98d633..a0a730bd9be6 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 @@ -28,6 +29,7 @@ #define FDT_PSTR_INITRD_STA "linux,initrd-start" #define FDT_PSTR_INITRD_END "linux,initrd-end" #define FDT_PSTR_BOOTARGS "bootargs" +#define FDT_PSTR_KASLR_SEED "kaslr-seed" const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_image_ops, @@ -46,11 +48,38 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) return kexec_image_post_load_cleanup_default(image); } +/* crng needs to have been initialized for providing kaslr-seed */ +static int random_ready; + +static void random_ready_notified(struct random_ready_callback *unused) +{ + random_ready = 1; +} + +static struct random_ready_callback random_ready_cb = { + .func = random_ready_notified, +}; + +static __init int init_random_ready_cb(void) +{ + int ret; + + ret = add_random_ready_callback(&random_ready_cb); + if (ret == -EALREADY) + random_ready = 1; + else if (ret) + pr_warn("failed to add a callback for random_ready\n"); + + return 0; +} +late_initcall(init_random_ready_cb) + static int setup_dtb(struct kimage *image, unsigned long initrd_load_addr, unsigned long initrd_len, char *cmdline, void *dtb) { int nodeoffset; + u64 value; int ret; nodeoffset = fdt_path_offset(dtb, "/chosen"); @@ -106,12 +135,27 @@ static int setup_dtb(struct kimage *image, return -EINVAL; } + /* add kaslr-seed */ + ret = fdt_delprop(dtb, nodeoffset, FDT_PSTR_KASLR_SEED); + if (ret && (ret != -FDT_ERR_NOTFOUND)) + return -EINVAL; + + if (random_ready) { + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop_u64(dtb, nodeoffset, FDT_PSTR_KASLR_SEED, + value); + if (ret) + return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL); + } else { + pr_notice("kaslr-seed won't be fed\n"); + } + return 0; } /* * More space needed so that we can add initrd, bootargs, - * userable-memory-range and elfcorehdr. + * userable-memory-range, elfcorehdr and kaslr-seed. */ #define DTB_EXTRA_SPACE 0x1000