From patchwork Fri Sep 15 10:59:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112711 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp470595qgf; Fri, 15 Sep 2017 03:57:57 -0700 (PDT) X-Received: by 10.99.120.202 with SMTP id t193mr24590947pgc.419.1505473077523; Fri, 15 Sep 2017 03:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473077; cv=none; d=google.com; s=arc-20160816; b=QKtjCPpmdBlhKFBbhTDQe72fLqHR8biTSLKApl7uXvl1dgQC9897o13dl6iD1QS5vQ VI38G4zCIieKqeMfes8yAYvJ4QyzI5WY0ZP2VgK5YkUuhRMQboNXWIMVonROkDtOlK8+ eij1Kv9rDzj6so7JQozEcarZYjq0pI4NJvqJV+DfrKqUlRdPO0ngxhTcQFJRNBvb4itZ 3z4gD6ARJPGssur1gchK/pdGmRa3IziSIL1KM9Fm/TAv1afOUShd1iijW/iCG8sUxIUN 7eLO/J6TFJdO3n8ma49mqWCVRdspIIwElpqGub/ZJg7LdmIO8E3C98aCfP9R8dxVgr9W UXhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fVNkswW2F9Q2QI2ZTaY0vlW/IrEbCVf8dY1cNKokZF4=; b=r6biBf9B9U08WCpZ4waD1aIhuTnlibdMjMMVZN0MeDQ7l5PqQuea5u9DdnLEGNQ70z aP3vbgvlo096S88yWMV+C0Isg2M3AP4ds6HG2VH7Oa8DVj5qlfQ54JWXbJrtCg7kI2Xn 4MCClHO5s4K/OedJHrimlxfMV0CGgCV8ClC5EgPQI1DQ0jihDR/3l2+ldeuEBzny1QHD FUvLULuEkcAvecgzxxKFNQjOaxSNhtrpKjTJcoJlYpmMmlurYPrj4/NcklXs7XVm7yWm 0xIHkbeMOPPy88vIvmvMMXr8FvJr03lblLgP4kBzoO3D61jQ8rUsylvlDiH9KogvHAdA xt1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h0sn+KNZ; 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 s7si498537plj.763.2017.09.15.03.57.57; Fri, 15 Sep 2017 03:57:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h0sn+KNZ; 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 S1751414AbdIOK5z (ORCPT + 26 others); Fri, 15 Sep 2017 06:57:55 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:46281 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdIOK5v (ORCPT ); Fri, 15 Sep 2017 06:57:51 -0400 Received: by mail-pf0-f181.google.com with SMTP id e199so1263348pfh.3 for ; Fri, 15 Sep 2017 03:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fVNkswW2F9Q2QI2ZTaY0vlW/IrEbCVf8dY1cNKokZF4=; b=h0sn+KNZGvkZmuzx8c0pN9cOwI+ykteLsoChxkW00OqD16Qz59pr2Gdsjy/h2cCYgx XvN4vnDWjmek0cvRy8UIu9QA7/rCKmAaKiLCWhqek1fC+LN4/tgVoWZ+bPTJ1VqtYsfU PmXq/7KvqkZdLUxSODNgva48F6PNpUcWagDR4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fVNkswW2F9Q2QI2ZTaY0vlW/IrEbCVf8dY1cNKokZF4=; b=YU5yreuI60ALhwHi+P8OhJQwmT+q6wZ4S8GuYLF/5QLG+kUlQDwfzDWaf2jKTSHNuQ mZDSUN/aIIDdA8MGxd+GjWX7Lo2eoTIK3a2QqySaOLTsa94981r52IJbWstXBNvo1T5C Hfdccf+kI0oUGhoR1nYfAiAk5VnGscSa/ReIbME4W4ICdqlt0xTW9uPWMre9ARMUSO7p uJC4yhnV+6rduIStgbtaiwNTQhJtMdEqe3/38EtISysVkO6JOGRblnIvyC53o75PdJ5V rMq4ALjgx1vP+fYuAQyUvBib+okfOEe949N4/cZ/mKQDMmgtvVZ2EiaiuQyoNcLGfvSA Bvig== X-Gm-Message-State: AHPjjUisjYtYujapHNK0UVGJdV9GzPtd2HYodmyQpyC8znUNgd+aFLUN HpAmaAXdFTfLla+0 X-Google-Smtp-Source: ADKCNb6ZSRLdRp8unjBKEj//K6I8JyXsI6YFCIkUD+J02E1gkmOtWOYkoa0OszmeNnMRq11Nj2DJxA== X-Received: by 10.98.204.201 with SMTP id j70mr24425741pfk.117.1505473071389; Fri, 15 Sep 2017 03:57:51 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x19sm2662329pfa.16.2017.09.15.03.57.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:57:50 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 01/10] include: pe.h: remove message[] from mz header definition Date: Fri, 15 Sep 2017 19:59:23 +0900 Message-Id: <20170915105932.25338-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org message[] field won't be part of the definition of mz header. This change is crucial for enabling kexec_file_load on arm64 because arm64's "Image" binary, as in PE format, doesn't have any data for it and accordingly the following check in pefile_parse_binary() will fail: chkaddr(cursor, mz->peaddr, sizeof(*pe)); Signed-off-by: AKASHI Takahiro Reviewed-by: Ard Biesheuvel Cc: David Howells Cc: Vivek Goyal Cc: Herbert Xu Cc: David S. Miller --- include/linux/pe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.14.1 diff --git a/include/linux/pe.h b/include/linux/pe.h index 143ce75be5f0..3482b18a48b5 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -166,7 +166,7 @@ struct mz_hdr { uint16_t oem_info; /* oem specific */ uint16_t reserved1[10]; /* reserved */ uint32_t peaddr; /* address of pe header */ - char message[64]; /* message to print */ + char message[]; /* message to print */ }; struct mz_reloc { From patchwork Fri Sep 15 10:59:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112712 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp470713qgf; Fri, 15 Sep 2017 03:58:06 -0700 (PDT) X-Received: by 10.98.63.16 with SMTP id m16mr23830600pfa.193.1505473085958; Fri, 15 Sep 2017 03:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473085; cv=none; d=google.com; s=arc-20160816; b=NWT9Jpqb7fQPodK3rRUDoA/b51FBA5AC6r/0vPXuPcAYmQXFMsiFHYjE5n+FRYHEGy fdIxo5FLIH8V/ec+umWzihvJGTZSJU/kymjIc+OE0UkDoXlGJ1lLKLek89uSGVjBWceE kJzOd19/Ms4OTR8gP9aeMcPwU8SMF1T4VPzKwX/qruXGV6OBAXydvUO4XoNWZuHfkEmW f+pN6WMgLu3ZQJ4eSy5gclEogM1Q+OaTq3Y+BpcYe6Bky8ew88zHvlds9xo0iVJ/hwzd Gm/WFZkIXkk4IRt53+5etgKMJR0UvhMCtqox5XE4TcYaYd2ilxmYAWuhpDHSTJSZZjoM 3Jcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Ni1zv4TS4KemAcbZg/ZChqjjHLQWmaU1Iruz6cZLyuY=; b=WbFnX7NIWuv1oIUiNKqMccwmGkR1IYtbK7m/CNZBY/aXuM9zhB8EjWxNeVEomwX5mC R60fFLuCCVXQgeP2UTvDOUGQJOerfZ1QjWtpD3pUu4NAtDhXzmxdXGk/Wscjh9QYQb5R j38AArc6QpPsHkf9TU3IOXEIo4/fEL+nWLPuPtBe+Kmilxe6DZudjDT8+qCm+7hBRY+x 2/PViwF54h7tiAdoFJpBAVYvnVNzbOpC7oV0nXltTKVaYk7keY01w/hXRwFCg/pyHLPO fBgg20/CXY+yAy06+yvP86GKTQAT7+mvhCov6m9sBTqBq/opYV78tcUt8+dVp/aXwPAm GlpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SRby9q8W; 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 s7si498537plj.763.2017.09.15.03.58.05; Fri, 15 Sep 2017 03:58:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SRby9q8W; 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 S1751457AbdIOK6D (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:03 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:51322 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdIOK6B (ORCPT ); Fri, 15 Sep 2017 06:58:01 -0400 Received: by mail-pg0-f54.google.com with SMTP id k193so1302338pgc.8 for ; Fri, 15 Sep 2017 03:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ni1zv4TS4KemAcbZg/ZChqjjHLQWmaU1Iruz6cZLyuY=; b=SRby9q8W5vuAmhCYfAw54YpWAr2Fei9Mkjt6nDD3G5xXFQqCCAaAE5lJOYw9zP30xq fEgw6pSh8plbf8vNUxGim4+NqHptfN2nz7eslp0Imj69Oo4TLqkOQFvYemqgTNos8hkO 7wVLJKh0eKs34PhUloGGQ3ZfPtzNqJs7bjR+w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ni1zv4TS4KemAcbZg/ZChqjjHLQWmaU1Iruz6cZLyuY=; b=bJaGpYb4n0UennaGpQFuaM68YjGkiWO74Z8Df3wl2ut9SE/quVkq0f5k10bGtv0pmN czYC+NfTJArvQqTWtcX3zoSEZ6sXdOXLuKUxmiC5wQ8QcQtGcjLwA4uq6FRZ/cu1rp/U cdgmF393clrH8h8BTI/tJTE6mgObL5uZk67uhxLUHNBJNHDA5gyQ7NBmGhR5aZMDDNKL rT5xv8NuRwiOPwksltS7EnsHMH82fs1/qUTvAh8nb6sPc/3zzlMBB3mwiFYASTOhCudS C3hPxNzBsDwcbZDs5Xq8u/oaeElMFpbvrXFrrReFDW9mskfiXoiXdCy/yggd6MDH8T4J SoAQ== X-Gm-Message-State: AHPjjUjMNHSxvR8xBAuI6ZtYIouMK8HjbziXw8KLzA3hvZ+u4pwgFMpd R/IOxF7vNiS80hhQ X-Google-Smtp-Source: ADKCNb7Xm8qdV3l2Cs77V2lCPM53fiqK286lhNqNmpc3mjMTw13Ab4LSgrtFzrK+U712gRUg1fZXWA== X-Received: by 10.84.238.198 with SMTP id l6mr26971470pln.152.1505473081000; Fri, 15 Sep 2017 03:58:01 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f11sm2405937pgt.65.2017.09.15.03.58.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:00 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , Linus Torvalds Subject: [PATCH v3 02/10] resource: add walk_system_ram_res_rev() Date: Fri, 15 Sep 2017 19:59:24 +0900 Message-Id: <20170915105932.25338-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function, being a variant of walk_system_ram_res() introduced in commit 8c86e70acead ("resource: provide new functions to walk through resources"), walks through a list of all the resources of System RAM in reversed order, i.e., from higher to lower. It will be used in kexec_file implementation on arm64. Signed-off-by: AKASHI Takahiro Cc: Vivek Goyal Cc: Andrew Morton Cc: Linus Torvalds --- include/linux/ioport.h | 3 +++ kernel/resource.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) -- 2.14.1 diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 6230064d7f95..9a212266299f 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -271,6 +271,9 @@ extern int walk_system_ram_res(u64 start, u64 end, void *arg, int (*func)(u64, u64, void *)); extern int +walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(u64, u64, void *)); +extern int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end, void *arg, int (*func)(u64, u64, void *)); diff --git a/kernel/resource.c b/kernel/resource.c index 9b5f04404152..572f2f91ce9c 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -469,6 +471,63 @@ int walk_system_ram_res(u64 start, u64 end, void *arg, return ret; } +int walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(u64, u64, void *)) +{ + struct resource res, *rams; + u64 orig_end; + int count, i; + int ret = -1; + + count = 16; /* initial */ + + /* create a list */ + rams = vmalloc(sizeof(struct resource) * count); + if (!rams) + return ret; + + res.start = start; + res.end = end; + res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + orig_end = res.end; + i = 0; + while ((res.start < res.end) && + (!find_next_iomem_res(&res, IORES_DESC_NONE, true))) { + if (i >= count) { + /* re-alloc */ + struct resource *rams_new; + int count_new; + + count_new = count + 16; + rams_new = vmalloc(sizeof(struct resource) * count_new); + if (!rams_new) + goto out; + + memcpy(rams_new, rams, count); + vfree(rams); + rams = rams_new; + count = count_new; + } + + rams[i].start = res.start; + rams[i++].end = res.end; + + res.start = res.end + 1; + res.end = orig_end; + } + + /* go reverse */ + for (i--; i >= 0; i--) { + ret = (*func)(rams[i].start, rams[i].end, arg); + if (ret) + break; + } + +out: + vfree(rams); + return ret; +} + #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY) /* From patchwork Fri Sep 15 10:59:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112713 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp470807qgf; Fri, 15 Sep 2017 03:58:13 -0700 (PDT) X-Received: by 10.101.67.200 with SMTP id n8mr24629148pgp.317.1505473093293; Fri, 15 Sep 2017 03:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473093; cv=none; d=google.com; s=arc-20160816; b=cN3njdz2xF7qz1gAnxGCRUb/NiqTvKtKkjRanLZRmZQK3Gd0rAcIiaFgke9xuuCIDw vX7Bo0FQKn/Fga8Ooo87/gVL5+iubMD5X8jqNUgBRX4ll49ufvfmI+VCn1JPh0p4nIQC 0VKGnhBkrEmspyjm9wLFEmimNL3c3xrqv1ajzsM6F6MwKZFxJVs/vgXOsNV3YYNi6W7l YcOQ0A4AhJVLTQi1IeSvf8zjQf5O4FSnfeMlyqHA6rPsE1+bxipISwqcUHbhKcNo7NjS b+j8XJUcD54RLX3yRrN9UJBaR9sKL6ecnFvDf6tKaSABXmdsyTTvJxmt5IldTZhnBsBD OA6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=ugNphDrZSJ9HUfacLH26VEP3GzufqzwOhLppALZCmac=; b=eq+2iKpgiLEpoQ+sjetmiDwj1pQds0FBngjhMvupxo7jpIdZv83pWLyW2DD8+amuEU XE7lN7j5zdUsL0ouvoy4M9jNX5ocx9yAucGw3q1EPTL3oYrkxGBaxYkvuiRcq4ZuwcIr ZxgPUw/WNVvYaf368Un8dAxJSoNRG+Z2rk0nZ84EO2Cmp2oi9hetNHPJwE7ppAN4H4Bv MMSCDogQqFD3ZVgzNDWIc21wErKJTFJZjU6Md4K2IEzkqPwddpmiQsa2nPk3XgMXmnRr B5JlflPaPqn7NjLh+1Uv6C6Nquaa+dCpq8G1EuZ13liKc5HG4DbH3UDC9uzpyaCP/ZiM m+kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XnNDrJz3; 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 h63si450463pgc.833.2017.09.15.03.58.12; Fri, 15 Sep 2017 03:58:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XnNDrJz3; 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 S1751494AbdIOK6J (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:09 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:49794 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdIOK6G (ORCPT ); Fri, 15 Sep 2017 06:58:06 -0400 Received: by mail-pf0-f169.google.com with SMTP id l188so1255665pfc.6 for ; Fri, 15 Sep 2017 03:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ugNphDrZSJ9HUfacLH26VEP3GzufqzwOhLppALZCmac=; b=XnNDrJz3hMH9f4sRNVZs3tfIberhkljpGxBjJz4ZSQaLzc5maEcNqXEvn1mXAgSEAw 9f5i2KbfT2zhcMK6/n9bosLm+A27I/WMm+YjBTipI14TdMbT02NllcTNachPqxOvSqyN hwFzWH4cicXlESHlUEq7bEpwPNznRBaESZkL4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ugNphDrZSJ9HUfacLH26VEP3GzufqzwOhLppALZCmac=; b=oxME08NFRdrlEHIgNWhAKEj17Gw+rPcRxw8+HUqCS6J6MLUw3xELV+hUn7etVj5kPW CdAqmwvZ7Zpe/gvI/rHtPK8EmEpXg9nB/qSfU7p5mkk3GDEXQB4tPCc+yC9iX2S3dH5L ZDozZNZqsJNZBtZbkcVtGIqadhIB62s2OhGzW43YFfq6ylJXUJMng0MaXBtTUZaExFAO G7rvaaVa0Qs02Oz/kYW3qH7xLp/y/l2+L2ysV5lAoMqRDyBYHJ8izdL3V/zjxfAE5Tnl /A45XTeuBuGg1aNGfGbKdL6HYFoQ7WkqGxGzEhph9K/d0ovH0dWo0wMUo/KVU0BXltw1 JG9g== X-Gm-Message-State: AHPjjUhGaI3E8Afp5XTkw0RhvjNFEoddYX7qt/vrOejpfcNF+yRE7d8Y txU1qb3XpskSPs9Z X-Google-Smtp-Source: ADKCNb6R2CgHa7TMalGh9hVP1AVS6t1Hyy1PcfVQ6t0GRUR004F/b4CLKVmElrsB16BJ/GyH+Nsz3g== X-Received: by 10.84.130.35 with SMTP id 32mr26972920plc.368.1505473085673; Fri, 15 Sep 2017 03:58:05 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id i63sm2221006pfk.34.2017.09.15.03.58.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:04 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 03/10] kexec_file: factor out arch_kexec_kernel_*() from x86, powerpc Date: Fri, 15 Sep 2017 19:59:25 +0900 Message-Id: <20170915105932.25338-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org arch_kexec_kernel_*() and arch_kimage_file_post_load_cleanup can now be duplicated among some architectures, so let's factor them out. Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He Cc: Michael Ellerman Cc: Thiago Jung Bauermann --- arch/powerpc/include/asm/kexec.h | 4 ++ arch/powerpc/kernel/machine_kexec_file_64.c | 36 ++---------------- arch/x86/kernel/machine_kexec_64.c | 59 +---------------------------- include/linux/kexec.h | 26 ++++++++++--- kernel/kexec_file.c | 52 +++++++++++++++++++------ 5 files changed, 70 insertions(+), 107 deletions(-) -- 2.14.1 diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h index 25668bc8cb2a..50810d24e38f 100644 --- a/arch/powerpc/include/asm/kexec.h +++ b/arch/powerpc/include/asm/kexec.h @@ -94,6 +94,10 @@ static inline bool kdump_in_progress(void) #ifdef CONFIG_KEXEC_FILE extern struct kexec_file_ops kexec_elf64_ops; +#define arch_kexec_kernel_image_probe arch_kexec_kernel_image_probe +int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, + unsigned long buf_len); + #ifdef CONFIG_IMA_KEXEC #define ARCH_HAS_KIMAGE_ARCH diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index 992c0d258e5d..5b7c4a3fbb50 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -31,8 +31,9 @@ #define SLAVE_CODE_SIZE 256 -static struct kexec_file_ops *kexec_file_loaders[] = { +struct kexec_file_ops *kexec_file_loaders[] = { &kexec_elf64_ops, + NULL }; int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, @@ -45,38 +46,7 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, if (image->type == KEXEC_TYPE_CRASH) return -ENOTSUPP; - for (i = 0; i < ARRAY_SIZE(kexec_file_loaders); i++) { - fops = kexec_file_loaders[i]; - if (!fops || !fops->probe) - continue; - - ret = fops->probe(buf, buf_len); - if (!ret) { - image->fops = fops; - return ret; - } - } - - return ret; -} - -void *arch_kexec_kernel_image_load(struct kimage *image) -{ - if (!image->fops || !image->fops->load) - return ERR_PTR(-ENOEXEC); - - return image->fops->load(image, image->kernel_buf, - image->kernel_buf_len, image->initrd_buf, - image->initrd_buf_len, image->cmdline_buf, - image->cmdline_buf_len); -} - -int arch_kimage_file_post_load_cleanup(struct kimage *image) -{ - if (!image->fops || !image->fops->cleanup) - return 0; - - return image->fops->cleanup(image->image_loader_data); + return kexec_kernel_image_probe(image, buf, buf_len); } /** diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index cb0a30473c23..f4df8315d001 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -30,8 +30,9 @@ #include #ifdef CONFIG_KEXEC_FILE -static struct kexec_file_ops *kexec_file_loaders[] = { +struct kexec_file_ops *kexec_file_loaders[] = { &kexec_bzImage64_ops, + NULL }; #endif @@ -361,62 +362,6 @@ void arch_crash_save_vmcoreinfo(void) /* arch-dependent functionality related to kexec file-based syscall */ #ifdef CONFIG_KEXEC_FILE -int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, - unsigned long buf_len) -{ - int i, ret = -ENOEXEC; - struct kexec_file_ops *fops; - - for (i = 0; i < ARRAY_SIZE(kexec_file_loaders); i++) { - fops = kexec_file_loaders[i]; - if (!fops || !fops->probe) - continue; - - ret = fops->probe(buf, buf_len); - if (!ret) { - image->fops = fops; - return ret; - } - } - - return ret; -} - -void *arch_kexec_kernel_image_load(struct kimage *image) -{ - vfree(image->arch.elf_headers); - image->arch.elf_headers = NULL; - - if (!image->fops || !image->fops->load) - return ERR_PTR(-ENOEXEC); - - return image->fops->load(image, image->kernel_buf, - image->kernel_buf_len, image->initrd_buf, - image->initrd_buf_len, image->cmdline_buf, - image->cmdline_buf_len); -} - -int arch_kimage_file_post_load_cleanup(struct kimage *image) -{ - if (!image->fops || !image->fops->cleanup) - return 0; - - return image->fops->cleanup(image->image_loader_data); -} - -#ifdef CONFIG_KEXEC_VERIFY_SIG -int arch_kexec_kernel_verify_sig(struct kimage *image, void *kernel, - unsigned long kernel_len) -{ - if (!image->fops || !image->fops->verify_sig) { - pr_debug("kernel loader does not support signature verification."); - return -EKEYREJECTED; - } - - return image->fops->verify_sig(kernel, kernel_len); -} -#endif - /* * Apply purgatory relocations. * diff --git a/include/linux/kexec.h b/include/linux/kexec.h index dd056fab9e35..4a2b24d94e04 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -134,6 +134,26 @@ struct kexec_file_ops { #endif }; +int kexec_kernel_image_probe(struct kimage *image, void *buf, + unsigned long buf_len); +void *kexec_kernel_image_load(struct kimage *image); +int kexec_kernel_post_load_cleanup(struct kimage *image); +int kexec_kernel_verify_sig(struct kimage *image, void *buf, + unsigned long buf_len); + +#ifndef arch_kexec_kernel_image_probe +#define arch_kexec_kernel_image_probe kexec_kernel_image_probe +#endif +#ifndef arch_kexec_kernel_image_load +#define arch_kexec_kernel_image_load kexec_kernel_image_load +#endif +#ifndef arch_kimage_file_post_load_cleanup +#define arch_kimage_file_post_load_cleanup kexec_kernel_post_load_cleanup +#endif +#ifndef arch_kexec_kernel_verify_sig +#define arch_kexec_kernel_verify_sig kexec_kernel_verify_sig +#endif + /** * struct kexec_buf - parameters for finding a place for a buffer in memory * @image: kexec image in which memory to search. @@ -276,12 +296,6 @@ int crash_shrink_memory(unsigned long new_size); size_t crash_get_memory_size(void); void crash_free_reserved_phys_range(unsigned long begin, unsigned long end); -int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf, - unsigned long buf_len); -void * __weak arch_kexec_kernel_image_load(struct kimage *image); -int __weak arch_kimage_file_post_load_cleanup(struct kimage *image); -int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, - unsigned long buf_len); int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, unsigned int relsec); int __weak arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 9f48f4412297..6203b54e04c5 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -26,30 +26,60 @@ #include #include "kexec_internal.h" +__weak struct kexec_file_ops *kexec_file_loaders[] = {NULL}; + static int kexec_calculate_store_digests(struct kimage *image); -/* Architectures can provide this probe function */ -int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf, - unsigned long buf_len) +int kexec_kernel_image_probe(struct kimage *image, void *buf, + unsigned long buf_len) { - return -ENOEXEC; + int i, ret = -ENOEXEC; + struct kexec_file_ops *fops; + + for (i = 0; ; i++) { + fops = kexec_file_loaders[i]; + if (!fops || !fops->probe) + break; + + ret = fops->probe(buf, buf_len); + if (!ret) { + image->fops = fops; + return ret; + } + } + + return ret; } -void * __weak arch_kexec_kernel_image_load(struct kimage *image) +void *kexec_kernel_image_load(struct kimage *image) { - return ERR_PTR(-ENOEXEC); + if (!image->fops || !image->fops->load) + return ERR_PTR(-ENOEXEC); + + return image->fops->load(image, image->kernel_buf, + image->kernel_buf_len, image->initrd_buf, + image->initrd_buf_len, image->cmdline_buf, + image->cmdline_buf_len); } -int __weak arch_kimage_file_post_load_cleanup(struct kimage *image) +int kexec_kernel_post_load_cleanup(struct kimage *image) { - return -EINVAL; + if (!image->fops || !image->fops->cleanup) + return 0; + + return image->fops->cleanup(image->image_loader_data); } #ifdef CONFIG_KEXEC_VERIFY_SIG -int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, - unsigned long buf_len) +int kexec_kernel_verify_sig(struct kimage *image, void *buf, + unsigned long buf_len) { - return -EKEYREJECTED; + if (!image->fops || !image->fops->verify_sig) { + pr_debug("kernel loader does not support signature verification.\n"); + return -EKEYREJECTED; + } + + return image->fops->verify_sig(buf, buf_len); } #endif From patchwork Fri Sep 15 10:59:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112714 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp470841qgf; Fri, 15 Sep 2017 03:58:16 -0700 (PDT) X-Received: by 10.84.233.70 with SMTP id k6mr4023949plt.138.1505473096103; Fri, 15 Sep 2017 03:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473096; cv=none; d=google.com; s=arc-20160816; b=bBLMe2gXc3gYVX2QYFVothDYhPiBnUkr0FMKF3XPSc7tf+gLo0sv+uxhjPwfgSBcym LjPlICvldaCgnwVBKnVZA+BhhYFjv5/lWRB7rq/PBdDRSY7hM9q1FUtf2DkKF3EMHoMz joza9QsE2335QP8iXe7+H6hk+4KlHlptYe+48DMkcdoOuLsIgFqHD6sfT9n9LRywG7Yp CUAmwDiFr+DJkqEbvB4eGmjYG4S2x2kX0DcSvoyeyFd82pCUhzMAe8QmK/O6xv1iGEZw 7zZFX3wE17aRAvNksLTWgxH/6nggWoM9fEw6eXz7U+jvV6b06nb8/P2jlrZWmXlracdy vgpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=rr0ZZI0mhiQhKzy7GIZ7DCQk9ikbUD23A9+2TqvUP+k=; b=LUw3GUbDsMsrCajXACKawl2pAzpwVrl2SsyKU2pr/qBaFPhxWickMjV+CpyCfsA1kr dbmg0ZaY7oIhutvlyqIm0QNTtCtsR2yzNNT8cxTZzTsHph2O2ZppnollJPivo9InKn3g oL3q90YiT9jGoaCh2Ug96+ERst0pWueqf0TA/GZfplyh41AeeQaXpZBbCrKSD9OvGXTW BEd2Rxa9NIMN87FE16+LdiilgOFc7htEekf4QOKeZToIgr+lBiyMgZIkUPiIEztFQISg 3VxzwMks/N4gdBbM1fCNR62SrAy1415JAptnDOvoVRdiskFIxvO1uFZSWpHeGskIKw7r Ei4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zv95Cw5y; 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 h63si450463pgc.833.2017.09.15.03.58.15; Fri, 15 Sep 2017 03:58:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zv95Cw5y; 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 S1751524AbdIOK6O (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:14 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:55624 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdIOK6L (ORCPT ); Fri, 15 Sep 2017 06:58:11 -0400 Received: by mail-pg0-f54.google.com with SMTP id b11so1296539pgn.12 for ; Fri, 15 Sep 2017 03:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rr0ZZI0mhiQhKzy7GIZ7DCQk9ikbUD23A9+2TqvUP+k=; b=Zv95Cw5yQOBvmwVaoOEpg7i5EkTd/91epywDGRQRErliwa/rLRR74RVp81m1BtkGjp esbP5CrabYysUWhMo0LnBSpWQkt+xuNOwE848twVWNAGOv3MPf2UnEVtgCf5IcXEuUGY hiclGFg574fzQe5PPfkXiNN7eGDp/Oo2gSPSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rr0ZZI0mhiQhKzy7GIZ7DCQk9ikbUD23A9+2TqvUP+k=; b=oM/OlT+dcTsIGqdP5Lv7KrCypuhZGPHCyng85VenDXCNC9sKRNgt/szEKjETg9dwaU Qwe2nwqHdSxy+VUHYKDb0xvT49MdGsFoSgZGXqNPXinXpQdEBeJrLtGn3yqQskW/yjk4 PVTo/txPuh1AYJDF1OuV7cYW2IpAptYBDp3rzB3ETAj7MmTHyjEN/cWG3OzdO2/2e09I y+21e0sAoL5RCvlkyBHA/PmgG14diSn7D4YKVR9f6yZdBoFuneYghYTBvDGtWJo1QeIa fvAtEhW9Gx8dpB2qaBRJgCX/nrA37MOPvMjtwJV94OvWd1K9KlrInnqsNnBd8VbCe2fr QqSg== X-Gm-Message-State: AHPjjUjGkMIdKR5rEY3rgAvMCTUN4CPClFJJHzeXrLmzredhPiPyR0Qt D3bB4bpaStPk7hpD X-Google-Smtp-Source: ADKCNb7ZpccTmXHJQWG4yM8DkTKTwoKa4DR6WkT0iDVe6a4H6R4U08kQDCcFWco9QfP+CGKJnmly9g== X-Received: by 10.84.129.226 with SMTP id b89mr27125670plb.228.1505473090955; Fri, 15 Sep 2017 03:58:10 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v31sm1932553pgn.43.2017.09.15.03.58.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:09 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 04/10] kexec_file: factor out crashdump elf header function from x86 Date: Fri, 15 Sep 2017 19:59:26 +0900 Message-Id: <20170915105932.25338-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org prepare_elf_headers() can also be useful for other architectures, including arm64. So let it factored out. Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- arch/x86/kernel/crash.c | 324 ------------------------------------------------ include/linux/kexec.h | 17 +++ kernel/kexec_file.c | 308 +++++++++++++++++++++++++++++++++++++++++++++ kernel/kexec_internal.h | 20 +++ 4 files changed, 345 insertions(+), 324 deletions(-) -- 2.14.1 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 44404e2307bb..3c6b880f6dbf 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -41,34 +40,6 @@ /* Alignment required for elf header segment */ #define ELF_CORE_HEADER_ALIGN 4096 -/* This primarily represents number of split ranges due to exclusion */ -#define CRASH_MAX_RANGES 16 - -struct crash_mem_range { - u64 start, end; -}; - -struct crash_mem { - unsigned int nr_ranges; - struct crash_mem_range ranges[CRASH_MAX_RANGES]; -}; - -/* Misc data about ram ranges needed to prepare elf headers */ -struct crash_elf_data { - struct kimage *image; - /* - * Total number of ram ranges we have after various adjustments for - * crash reserved region, etc. - */ - unsigned int max_nr_ranges; - - /* Pointer to elf header */ - void *ehdr; - /* Pointer to next phdr */ - void *bufp; - struct crash_mem mem; -}; - /* Used while preparing memory map entries for second kernel */ struct crash_memmap_data { struct boot_params *params; @@ -209,301 +180,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs) } #ifdef CONFIG_KEXEC_FILE -static int get_nr_ram_ranges_callback(u64 start, u64 end, void *arg) -{ - unsigned int *nr_ranges = arg; - - (*nr_ranges)++; - return 0; -} - - -/* Gather all the required information to prepare elf headers for ram regions */ -static void fill_up_crash_elf_data(struct crash_elf_data *ced, - struct kimage *image) -{ - unsigned int nr_ranges = 0; - - ced->image = image; - - walk_system_ram_res(0, -1, &nr_ranges, - get_nr_ram_ranges_callback); - - ced->max_nr_ranges = nr_ranges; - - /* Exclusion of crash region could split memory ranges */ - ced->max_nr_ranges++; - - /* If crashk_low_res is not 0, another range split possible */ - if (crashk_low_res.end) - ced->max_nr_ranges++; -} - -static int exclude_mem_range(struct crash_mem *mem, - unsigned long long mstart, unsigned long long mend) -{ - int i, j; - unsigned long long start, end; - struct crash_mem_range temp_range = {0, 0}; - - for (i = 0; i < mem->nr_ranges; i++) { - start = mem->ranges[i].start; - end = mem->ranges[i].end; - - if (mstart > end || mend < start) - continue; - - /* Truncate any area outside of range */ - if (mstart < start) - mstart = start; - if (mend > end) - mend = end; - - /* Found completely overlapping range */ - if (mstart == start && mend == end) { - mem->ranges[i].start = 0; - mem->ranges[i].end = 0; - if (i < mem->nr_ranges - 1) { - /* Shift rest of the ranges to left */ - for (j = i; j < mem->nr_ranges - 1; j++) { - mem->ranges[j].start = - mem->ranges[j+1].start; - mem->ranges[j].end = - mem->ranges[j+1].end; - } - } - mem->nr_ranges--; - return 0; - } - - if (mstart > start && mend < end) { - /* Split original range */ - mem->ranges[i].end = mstart - 1; - temp_range.start = mend + 1; - temp_range.end = end; - } else if (mstart != start) - mem->ranges[i].end = mstart - 1; - else - mem->ranges[i].start = mend + 1; - break; - } - - /* If a split happend, add the split to array */ - if (!temp_range.end) - return 0; - - /* Split happened */ - if (i == CRASH_MAX_RANGES - 1) { - pr_err("Too many crash ranges after split\n"); - return -ENOMEM; - } - - /* Location where new range should go */ - j = i + 1; - if (j < mem->nr_ranges) { - /* Move over all ranges one slot towards the end */ - for (i = mem->nr_ranges - 1; i >= j; i--) - mem->ranges[i + 1] = mem->ranges[i]; - } - - mem->ranges[j].start = temp_range.start; - mem->ranges[j].end = temp_range.end; - mem->nr_ranges++; - return 0; -} - -/* - * Look for any unwanted ranges between mstart, mend and remove them. This - * might lead to split and split ranges are put in ced->mem.ranges[] array - */ -static int elf_header_exclude_ranges(struct crash_elf_data *ced, - unsigned long long mstart, unsigned long long mend) -{ - struct crash_mem *cmem = &ced->mem; - int ret = 0; - - memset(cmem->ranges, 0, sizeof(cmem->ranges)); - - cmem->ranges[0].start = mstart; - cmem->ranges[0].end = mend; - cmem->nr_ranges = 1; - - /* Exclude crashkernel region */ - ret = exclude_mem_range(cmem, crashk_res.start, crashk_res.end); - if (ret) - return ret; - - if (crashk_low_res.end) { - ret = exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end); - if (ret) - return ret; - } - - return ret; -} - -static int prepare_elf64_ram_headers_callback(u64 start, u64 end, void *arg) -{ - struct crash_elf_data *ced = arg; - Elf64_Ehdr *ehdr; - Elf64_Phdr *phdr; - unsigned long mstart, mend; - struct kimage *image = ced->image; - struct crash_mem *cmem; - int ret, i; - - ehdr = ced->ehdr; - - /* Exclude unwanted mem ranges */ - ret = elf_header_exclude_ranges(ced, start, end); - if (ret) - return ret; - - /* Go through all the ranges in ced->mem.ranges[] and prepare phdr */ - cmem = &ced->mem; - - for (i = 0; i < cmem->nr_ranges; i++) { - mstart = cmem->ranges[i].start; - mend = cmem->ranges[i].end; - - phdr = ced->bufp; - ced->bufp += sizeof(Elf64_Phdr); - - phdr->p_type = PT_LOAD; - phdr->p_flags = PF_R|PF_W|PF_X; - phdr->p_offset = mstart; - - /* - * If a range matches backup region, adjust offset to backup - * segment. - */ - if (mstart == image->arch.backup_src_start && - (mend - mstart + 1) == image->arch.backup_src_sz) - phdr->p_offset = image->arch.backup_load_addr; - - phdr->p_paddr = mstart; - phdr->p_vaddr = (unsigned long long) __va(mstart); - phdr->p_filesz = phdr->p_memsz = mend - mstart + 1; - phdr->p_align = 0; - ehdr->e_phnum++; - pr_debug("Crash PT_LOAD elf header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n", - phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, - ehdr->e_phnum, phdr->p_offset); - } - - return ret; -} - -static int prepare_elf64_headers(struct crash_elf_data *ced, - void **addr, unsigned long *sz) -{ - Elf64_Ehdr *ehdr; - Elf64_Phdr *phdr; - unsigned long nr_cpus = num_possible_cpus(), nr_phdr, elf_sz; - unsigned char *buf, *bufp; - unsigned int cpu; - unsigned long long notes_addr; - int ret; - - /* extra phdr for vmcoreinfo elf note */ - nr_phdr = nr_cpus + 1; - nr_phdr += ced->max_nr_ranges; - - /* - * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping - * area on x86_64 (ffffffff80000000 - ffffffffa0000000). - * I think this is required by tools like gdb. So same physical - * memory will be mapped in two elf headers. One will contain kernel - * text virtual addresses and other will have __va(physical) addresses. - */ - - nr_phdr++; - elf_sz = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); - elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); - - buf = vzalloc(elf_sz); - if (!buf) - return -ENOMEM; - - bufp = buf; - ehdr = (Elf64_Ehdr *)bufp; - bufp += sizeof(Elf64_Ehdr); - memcpy(ehdr->e_ident, ELFMAG, SELFMAG); - ehdr->e_ident[EI_CLASS] = ELFCLASS64; - ehdr->e_ident[EI_DATA] = ELFDATA2LSB; - ehdr->e_ident[EI_VERSION] = EV_CURRENT; - ehdr->e_ident[EI_OSABI] = ELF_OSABI; - memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD); - ehdr->e_type = ET_CORE; - ehdr->e_machine = ELF_ARCH; - ehdr->e_version = EV_CURRENT; - ehdr->e_phoff = sizeof(Elf64_Ehdr); - ehdr->e_ehsize = sizeof(Elf64_Ehdr); - ehdr->e_phentsize = sizeof(Elf64_Phdr); - - /* Prepare one phdr of type PT_NOTE for each present cpu */ - for_each_present_cpu(cpu) { - phdr = (Elf64_Phdr *)bufp; - bufp += sizeof(Elf64_Phdr); - phdr->p_type = PT_NOTE; - notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); - phdr->p_offset = phdr->p_paddr = notes_addr; - phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t); - (ehdr->e_phnum)++; - } - - /* Prepare one PT_NOTE header for vmcoreinfo */ - phdr = (Elf64_Phdr *)bufp; - bufp += sizeof(Elf64_Phdr); - phdr->p_type = PT_NOTE; - phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note(); - phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE; - (ehdr->e_phnum)++; - -#ifdef CONFIG_X86_64 - /* Prepare PT_LOAD type program header for kernel text region */ - phdr = (Elf64_Phdr *)bufp; - bufp += sizeof(Elf64_Phdr); - phdr->p_type = PT_LOAD; - phdr->p_flags = PF_R|PF_W|PF_X; - phdr->p_vaddr = (Elf64_Addr)_text; - phdr->p_filesz = phdr->p_memsz = _end - _text; - phdr->p_offset = phdr->p_paddr = __pa_symbol(_text); - (ehdr->e_phnum)++; -#endif - - /* Prepare PT_LOAD headers for system ram chunks. */ - ced->ehdr = ehdr; - ced->bufp = bufp; - ret = walk_system_ram_res(0, -1, ced, - prepare_elf64_ram_headers_callback); - if (ret < 0) - return ret; - - *addr = buf; - *sz = elf_sz; - return 0; -} - -/* Prepare elf headers. Return addr and size */ -static int prepare_elf_headers(struct kimage *image, void **addr, - unsigned long *sz) -{ - struct crash_elf_data *ced; - int ret; - - ced = kzalloc(sizeof(*ced), GFP_KERNEL); - if (!ced) - return -ENOMEM; - - fill_up_crash_elf_data(ced, image); - - /* By default prepare 64bit headers */ - ret = prepare_elf64_headers(ced, addr, sz); - kfree(ced); - return ret; -} - static int add_e820_entry(struct boot_params *params, struct e820_entry *entry) { unsigned int nr_e820_entries; diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 4a2b24d94e04..7547a3c1f94e 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -182,6 +182,23 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *)); extern int kexec_add_buffer(struct kexec_buf *kbuf); int kexec_locate_mem_hole(struct kexec_buf *kbuf); +extern int prepare_elf_headers(struct kimage *image, void **addr, + unsigned long *sz); + +/* This primarily represents number of split ranges due to exclusion */ +#define CRASH_MAX_RANGES 16 + +struct crash_mem_range { + u64 start, end; +}; + +struct crash_mem { + unsigned int nr_ranges; + struct crash_mem_range ranges[CRASH_MAX_RANGES]; +}; + +extern int exclude_mem_range(struct crash_mem *mem, + unsigned long long mstart, unsigned long long mend); #endif /* CONFIG_KEXEC_FILE */ struct kimage { diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 6203b54e04c5..6a0e31e175af 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -22,6 +22,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include "kexec_internal.h" @@ -1051,3 +1056,306 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name, return 0; } + +static int get_nr_ram_ranges_callback(u64 start, u64 end, void *arg) +{ + unsigned int *nr_ranges = arg; + + (*nr_ranges)++; + return 0; +} + + +/* Gather all the required information to prepare elf headers for ram regions */ +static void fill_up_crash_elf_data(struct crash_elf_data *ced, + struct kimage *image) +{ + unsigned int nr_ranges = 0; + + ced->image = image; + + walk_system_ram_res(0, -1, &nr_ranges, + get_nr_ram_ranges_callback); + + ced->max_nr_ranges = nr_ranges; + + /* Exclusion of crash region could split memory ranges */ + ced->max_nr_ranges++; + +#ifdef CONFIG_X86_64 + /* If crashk_low_res is not 0, another range split possible */ + if (crashk_low_res.end) + ced->max_nr_ranges++; +#endif +} + +int exclude_mem_range(struct crash_mem *mem, + unsigned long long mstart, unsigned long long mend) +{ + int i, j; + unsigned long long start, end; + struct crash_mem_range temp_range = {0, 0}; + + for (i = 0; i < mem->nr_ranges; i++) { + start = mem->ranges[i].start; + end = mem->ranges[i].end; + + if (mstart > end || mend < start) + continue; + + /* Truncate any area outside of range */ + if (mstart < start) + mstart = start; + if (mend > end) + mend = end; + + /* Found completely overlapping range */ + if (mstart == start && mend == end) { + mem->ranges[i].start = 0; + mem->ranges[i].end = 0; + if (i < mem->nr_ranges - 1) { + /* Shift rest of the ranges to left */ + for (j = i; j < mem->nr_ranges - 1; j++) { + mem->ranges[j].start = + mem->ranges[j+1].start; + mem->ranges[j].end = + mem->ranges[j+1].end; + } + } + mem->nr_ranges--; + return 0; + } + + if (mstart > start && mend < end) { + /* Split original range */ + mem->ranges[i].end = mstart - 1; + temp_range.start = mend + 1; + temp_range.end = end; + } else if (mstart != start) + mem->ranges[i].end = mstart - 1; + else + mem->ranges[i].start = mend + 1; + break; + } + + /* If a split happened, add the split to array */ + if (!temp_range.end) + return 0; + + /* Split happened */ + if (i == CRASH_MAX_RANGES - 1) { + pr_err("Too many crash ranges after split\n"); + return -ENOMEM; + } + + /* Location where new range should go */ + j = i + 1; + if (j < mem->nr_ranges) { + /* Move over all ranges one slot towards the end */ + for (i = mem->nr_ranges - 1; i >= j; i--) + mem->ranges[i + 1] = mem->ranges[i]; + } + + mem->ranges[j].start = temp_range.start; + mem->ranges[j].end = temp_range.end; + mem->nr_ranges++; + return 0; +} + +/* + * Look for any unwanted ranges between mstart, mend and remove them. This + * might lead to split and split ranges are put in ced->mem.ranges[] array + */ +static int elf_header_exclude_ranges(struct crash_elf_data *ced, + unsigned long long mstart, unsigned long long mend) +{ + struct crash_mem *cmem = &ced->mem; + int ret = 0; + + memset(cmem->ranges, 0, sizeof(cmem->ranges)); + + cmem->ranges[0].start = mstart; + cmem->ranges[0].end = mend; + cmem->nr_ranges = 1; + + /* Exclude crashkernel region */ + ret = exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + if (ret) + return ret; + +#ifdef CONFIG_X86_64 + if (crashk_low_res.end) { + ret = exclude_mem_range(cmem, crashk_low_res.start, + crashk_low_res.end); + if (ret) + return ret; + } +#endif + + return ret; +} + +static int prepare_elf64_ram_headers_callback(u64 start, u64 end, void *arg) +{ + struct crash_elf_data *ced = arg; + Elf64_Ehdr *ehdr; + Elf64_Phdr *phdr; + unsigned long mstart, mend; +#ifdef CONFIG_X86_64 + struct kimage *image = ced->image; +#endif + struct crash_mem *cmem; + int ret, i; + + ehdr = ced->ehdr; + + /* Exclude unwanted mem ranges */ + ret = elf_header_exclude_ranges(ced, start, end); + if (ret) + return ret; + + /* Go through all the ranges in ced->mem.ranges[] and prepare phdr */ + cmem = &ced->mem; + + for (i = 0; i < cmem->nr_ranges; i++) { + mstart = cmem->ranges[i].start; + mend = cmem->ranges[i].end; + + phdr = ced->bufp; + ced->bufp += sizeof(Elf64_Phdr); + + phdr->p_type = PT_LOAD; + phdr->p_flags = PF_R|PF_W|PF_X; + phdr->p_offset = mstart; + +#ifdef CONFIG_X86_64 + /* + * If a range matches backup region, adjust offset to backup + * segment. + */ + if (mstart == image->arch.backup_src_start && + (mend - mstart + 1) == image->arch.backup_src_sz) + phdr->p_offset = image->arch.backup_load_addr; +#endif + + phdr->p_paddr = mstart; + phdr->p_vaddr = (unsigned long long) __va(mstart); + phdr->p_filesz = phdr->p_memsz = mend - mstart + 1; + phdr->p_align = 0; + ehdr->e_phnum++; + pr_debug("Crash PT_LOAD elf header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n", + phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, + ehdr->e_phnum, phdr->p_offset); + } + + return ret; +} + +static int prepare_elf64_headers(struct crash_elf_data *ced, + void **addr, unsigned long *sz) +{ + Elf64_Ehdr *ehdr; + Elf64_Phdr *phdr; + unsigned long nr_cpus = num_possible_cpus(), nr_phdr, elf_sz; + unsigned char *buf, *bufp; + unsigned int cpu; + unsigned long long notes_addr; + int ret; + + /* extra phdr for vmcoreinfo elf note */ + nr_phdr = nr_cpus + 1; + nr_phdr += ced->max_nr_ranges; + + /* + * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping + * area on x86_64 (ffffffff80000000 - ffffffffa0000000). + * I think this is required by tools like gdb. So same physical + * memory will be mapped in two elf headers. One will contain kernel + * text virtual addresses and other will have __va(physical) addresses. + */ + + nr_phdr++; + elf_sz = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); + elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); + + buf = vzalloc(elf_sz); + if (!buf) + return -ENOMEM; + + bufp = buf; + ehdr = (Elf64_Ehdr *)bufp; + bufp += sizeof(Elf64_Ehdr); + memcpy(ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] = ELFCLASS64; + ehdr->e_ident[EI_DATA] = ELFDATA2LSB; + ehdr->e_ident[EI_VERSION] = EV_CURRENT; + ehdr->e_ident[EI_OSABI] = ELF_OSABI; + memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD); + ehdr->e_type = ET_CORE; + ehdr->e_machine = ELF_ARCH; + ehdr->e_version = EV_CURRENT; + ehdr->e_phoff = sizeof(Elf64_Ehdr); + ehdr->e_ehsize = sizeof(Elf64_Ehdr); + ehdr->e_phentsize = sizeof(Elf64_Phdr); + + /* Prepare one phdr of type PT_NOTE for each present cpu */ + for_each_present_cpu(cpu) { + phdr = (Elf64_Phdr *)bufp; + bufp += sizeof(Elf64_Phdr); + phdr->p_type = PT_NOTE; + notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); + phdr->p_offset = phdr->p_paddr = notes_addr; + phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t); + (ehdr->e_phnum)++; + } + + /* Prepare one PT_NOTE header for vmcoreinfo */ + phdr = (Elf64_Phdr *)bufp; + bufp += sizeof(Elf64_Phdr); + phdr->p_type = PT_NOTE; + phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note(); + phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE; + (ehdr->e_phnum)++; + +#ifdef CONFIG_X86_64 + /* Prepare PT_LOAD type program header for kernel text region */ + phdr = (Elf64_Phdr *)bufp; + bufp += sizeof(Elf64_Phdr); + phdr->p_type = PT_LOAD; + phdr->p_flags = PF_R|PF_W|PF_X; + phdr->p_vaddr = (Elf64_Addr)_text; + phdr->p_filesz = phdr->p_memsz = _end - _text; + phdr->p_offset = phdr->p_paddr = __pa_symbol(_text); + (ehdr->e_phnum)++; +#endif + + /* Prepare PT_LOAD headers for system ram chunks. */ + ced->ehdr = ehdr; + ced->bufp = bufp; + ret = walk_system_ram_res(0, -1, ced, + prepare_elf64_ram_headers_callback); + if (ret < 0) + return ret; + + *addr = buf; + *sz = elf_sz; + return 0; +} + +/* Prepare elf headers. Return addr and size */ +int prepare_elf_headers(struct kimage *image, void **addr, unsigned long *sz) +{ + struct crash_elf_data *ced; + int ret; + + ced = kzalloc(sizeof(*ced), GFP_KERNEL); + if (!ced) + return -ENOMEM; + + fill_up_crash_elf_data(ced, image); + + /* By default prepare 64bit headers */ + ret = prepare_elf64_headers(ced, addr, sz); + kfree(ced); + return ret; +} diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h index 50dfcb039a41..3c7a034f1fe1 100644 --- a/kernel/kexec_internal.h +++ b/kernel/kexec_internal.h @@ -16,6 +16,26 @@ extern struct mutex kexec_mutex; #ifdef CONFIG_KEXEC_FILE #include + +/* Alignment required for elf header segment */ +#define ELF_CORE_HEADER_ALIGN 4096 + +/* Misc data about ram ranges needed to prepare elf headers */ +struct crash_elf_data { + struct kimage *image; + /* + * Total number of ram ranges we have after various adjustments for + * crash reserved region, etc. + */ + unsigned int max_nr_ranges; + + /* Pointer to elf header */ + void *ehdr; + /* Pointer to next phdr */ + void *bufp; + struct crash_mem mem; +}; + void kimage_file_post_load_cleanup(struct kimage *image); extern char kexec_purgatory[]; extern size_t kexec_purgatory_size; From patchwork Fri Sep 15 10:59:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112715 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp470944qgf; Fri, 15 Sep 2017 03:58:25 -0700 (PDT) X-Received: by 10.84.143.129 with SMTP id 1mr2570952plz.304.1505473104961; Fri, 15 Sep 2017 03:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473104; cv=none; d=google.com; s=arc-20160816; b=Rok8heU9f+1dV48i44kVhGBZ8KRL0rsscpYgAw4X+N6czZsVD+oR/e14CCUWIvM2Fe Do1aC9U/Kw4P9dGaFNetkILUvoubqW08jiuUJm5mOfPJXRfbBQkGfL6aXhAiVJcM0tlk +3v+hLtPZgpZXM4SpaB80/+71XQdupoy/zOpcsosErNE/TmxXOUY8V5SNLTTHqu0q6cQ 2QBI3PiVjkSLr9cfI93NbcjV4hHSSBQvpbNqNAKRqUKZ7g1jat3/5nxT2byHj5cFbHHK uWagJkJUtdFnsVsynC7nIsDyeosk9Q+ll1lDKlkPFeoJPg6tCoKtqm8bJBzBskewL7uq OYIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=XQ2hfwuqOxZtO/79mPkNiInqsdauHyfcRiwhgMReb/c=; b=j/uzRw5GK+OwXxucySunF3MqlFk7NcS9AFcE/96cLp6Ta/qDaLuMi+m8BrL3028BYe rWwzjj/mGp3+vvSioAbnGru0mz8fAW3weffTgzSrmNtG6Rc10r0154kHO89TvrLFgrDI zgZJ1W5+C7+xl4JBsU2Ups88jppYqh07FUIJHQR5wx4lYZHkZmodcOGpnK5azxcW34t8 KH2JoQrXlwpRNGGwwJ126+K+WZB48Ewev2ih/6Hy5owT/OVBQwukVQISk3NeSVx3Y+za GA/M25PbsqEAS0YWB3zp7n5cyqUPMQIStL195WJAyUEqBgJSFLf0wDowD43L68hopjgQ 7I/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IkReyxmU; 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 z27si479373pgc.53.2017.09.15.03.58.24; Fri, 15 Sep 2017 03:58:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IkReyxmU; 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 S1751571AbdIOK6X (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:23 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:55208 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751537AbdIOK6U (ORCPT ); Fri, 15 Sep 2017 06:58:20 -0400 Received: by mail-pf0-f173.google.com with SMTP id d187so1251040pfg.11 for ; Fri, 15 Sep 2017 03:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XQ2hfwuqOxZtO/79mPkNiInqsdauHyfcRiwhgMReb/c=; b=IkReyxmUW+gLt1efsMpfMKv5A6h7dLgY+J5agJeAGAWyy7QIyVgjXxDyR9oGiEuQV+ lTltlZYU/rdwqQyY+yIARim8ji8uwFUyXTsggDWf9KiUHzD+0q9nN8RqrH/Im0SproxS oKRGASGinwdze2NAr2YbwcMopLdS9BnZCkc+I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XQ2hfwuqOxZtO/79mPkNiInqsdauHyfcRiwhgMReb/c=; b=VFvjczFf6RVY3OBfF1m8RloRJOkxnkYunWIXGgmBRWvLoFjD5oB5HEf1ZE+bDxzPCW cRUv/q6qbP9nN4ybC/fPLWUvZFS4QQzeSvBkhWF1QUhQP53G1v0nkHgv1VKebcJJad5I XzUU1ZyK4GVzXBd3wCrZHkzoGZvce7rNz3L8Db01b/H/8wlR3w9a/00h2nOScWYt9eRK ESHeotb++Z1X7ZN9FW9bOsFav07e+K+pl529mfNhjU1jew/nHRvBGYXaOWR5OdhFzD0K zmuq5bFIMR+McQgZrlU7YXLI/8i73ehS7y44p64MUoE499UHiuQd5qWxyHc+tcoawvSM 8W0w== X-Gm-Message-State: AHPjjUhwv6FkOfz1j8z3NTHi9N5B6cmumXo7nSZDQTrHDG19WDO9+11p Y495j5BZrPfer9uv X-Google-Smtp-Source: ADKCNb6AOFIOXm2BOeqdR/mCjNeMe1QaiBKti13cPTuihCehFQyHobuqdWPKuR+ANeGvYkgTlg2CEg== X-Received: by 10.99.126.23 with SMTP id z23mr23727399pgc.156.1505473099512; Fri, 15 Sep 2017 03:58:19 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t81sm2363221pfg.154.2017.09.15.03.58.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:17 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 05/10] asm-generic: add kexec_file_load system call to unistd.h Date: Fri, 15 Sep 2017 19:59:27 +0900 Message-Id: <20170915105932.25338-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The initial user of this system call number is arm64. Signed-off-by: AKASHI Takahiro Acked-by: Arnd Bergmann --- include/uapi/asm-generic/unistd.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.14.1 diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 061185a5eb51..086697fe3917 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -731,9 +731,11 @@ __SYSCALL(__NR_pkey_alloc, sys_pkey_alloc) __SYSCALL(__NR_pkey_free, sys_pkey_free) #define __NR_statx 291 __SYSCALL(__NR_statx, sys_statx) +#define __NR_kexec_file_load 292 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 292 +#define __NR_syscalls 293 /* * All syscalls below here should go away really, From patchwork Fri Sep 15 10:59:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112716 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp471001qgf; Fri, 15 Sep 2017 03:58:29 -0700 (PDT) X-Received: by 10.84.224.141 with SMTP id s13mr27371131plj.409.1505473109149; Fri, 15 Sep 2017 03:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473109; cv=none; d=google.com; s=arc-20160816; b=sJEuKsxLjue07aonqPJM1UpI325UkWO/+wOu4GgU3wkTRiSQKyILoDusQ0PEdU8X3i 6LazcjPfppzYcw37qaak8dQRblaKD7ciWuMBR3iw3J73q76Xlmxn3ajbHDtks+0DFLTI GuR5LVBEdqwkYKT3RcWOUOtgAEQfbF28gO/0PwgAWUjwDRAuaQ53+a1RQ0mtLz3SC3a7 28blou7T6Htc2XecgsjbbJyaMD+PZyzl6DM0oyokRSDK2zkd9er9K5CR8Vf4ThkrwVZN r0VmGIXCzg6GkREerxluPf9WTckI4d8t+WUGAnfp9ff3y5b9QBX86VYX+kDWKHVkSHk9 fZhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=7jakUu5zZVUZd6l4cWf4+pL5rKleWCl55w/nm/hAfdo=; b=iJ86pKru8WAFXRhaETcDoPVdAm/z9f/FsxrLTbsD1UfYWob5lDRnLbo2YAf92w9MEk SFPIMyZbhKJrig/ByxsWo/3RM/amaasLESPgajSyNjFu1HlXLW8gLGaIkcQmHApp0mml u9LZGDsYQttJIOhw45mKMo+CcpN8VCRKg28Um94ebJ0QXH1/JqGnLVRQs1cmpcjsi30i cqrztr3TaBwoDuUFE4KXD5a0qXhNBEGJSTroi5Ar1KwOuqCC3R8bCGtxaCV71Coz4kci swtye2dipSR0H/GbBB3y1JmNvw5MsBvB6xbIcGDn9hKgjt2yoAh/qJNtbTt7O1b8ERX9 1Ufw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y3jsVQpv; 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 z27si479373pgc.53.2017.09.15.03.58.28; Fri, 15 Sep 2017 03:58:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y3jsVQpv; 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 S1751610AbdIOK60 (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:26 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:51344 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751575AbdIOK6Y (ORCPT ); Fri, 15 Sep 2017 06:58:24 -0400 Received: by mail-pg0-f43.google.com with SMTP id k193so1302706pgc.8 for ; Fri, 15 Sep 2017 03:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7jakUu5zZVUZd6l4cWf4+pL5rKleWCl55w/nm/hAfdo=; b=Y3jsVQpvEZQogOPhkmXs9QONBu+09E/eYC/vXe7WDSfcAWYwanNyvA+XEdRwVhMI8W I+xcmZtksT3p+g0Lt70dUigdGFsJkrNOmxK2jG/w1Z9cxwshLt1FUooKOSeAmjQcCB/T mfzRuCGBOf761KICx8xIsFKSRRQXjLF5kYY/I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7jakUu5zZVUZd6l4cWf4+pL5rKleWCl55w/nm/hAfdo=; b=niVyxt+r7ymoAliq/MuYkcMtc0i6qioWH8Jm73ctNL1JODY+LVMrXPUfgaoFnguEVr 9DoR4o+QMmFAjdbomTblyARXczfpDJ7SsrzxXtg36pWyBft5yZRvMYWeOhJI/xrH3ahl xWTiWazGSPz97FSy/QyVPADX0dqWumbLwPO8VQg7kaCaggL1P7kAE1PbUNrIx0LqHhvH P9egj+B0tjplzqlbjJvEFc34XS0hnV/3CNxWtAr0ZE92ujrAbBCr3PDVZbkYk4U8t58W Z9X1EiMFAoVtV1yA+I71a5HGqwEuCgHl5b1LMKl+8E7C2YfyP+4wU8/SeqgFSjOlV8Ga taTQ== X-Gm-Message-State: AHPjjUgH3JCb334RGmeuasOcMazhSECEgahqvj1Wr4tt22qafLhswuus aosnoO08PWlVVg9W X-Google-Smtp-Source: ADKCNb7jgGIBgrA6lR9yOUQuY9/64uTXrsHhjdDRG7a3DzRlT3TqKfFPr7pmZCcgI+sJxtASXBq3WQ== X-Received: by 10.84.236.76 with SMTP id h12mr27771505pln.181.1505473103776; Fri, 15 Sep 2017 03:58:23 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x189sm1944768pfx.188.2017.09.15.03.58.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:23 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 06/10] arm64: kexec_file: create purgatory Date: Fri, 15 Sep 2017 19:59:28 +0900 Message-Id: <20170915105932.25338-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a basic purgatory, or a kind of glue code between the two kernels, for arm64. Since purgatory is assumed to be relocatable (not executable) object by kexec generic code, arch_kexec_apply_relocations_add() is required in general. Arm64's purgatory, however, is a simple asm and all the references can be resolved as local, no re-linking is needed here. Please note that even if we don't support digest check at purgatory we need purgatory_sha_regions and purgatory_sha256_digest as they are referenced by generic kexec code. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Makefile | 1 + arch/arm64/purgatory/Makefile | 24 +++++++++++++++++++ arch/arm64/purgatory/entry.S | 55 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 arch/arm64/purgatory/Makefile create mode 100644 arch/arm64/purgatory/entry.S -- 2.14.1 diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 9b41f1e3b1a0..429f60728c0a 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -105,6 +105,7 @@ core-$(CONFIG_XEN) += arch/arm64/xen/ core-$(CONFIG_CRYPTO) += arch/arm64/crypto/ libs-y := arch/arm64/lib/ $(libs-y) core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a +core-$(CONFIG_KEXEC_FILE) += arch/arm64/purgatory/ # Default target when executing plain make boot := arch/arm64/boot diff --git a/arch/arm64/purgatory/Makefile b/arch/arm64/purgatory/Makefile new file mode 100644 index 000000000000..c2127a2cbd51 --- /dev/null +++ b/arch/arm64/purgatory/Makefile @@ -0,0 +1,24 @@ +OBJECT_FILES_NON_STANDARD := y + +purgatory-y := entry.o + +targets += $(purgatory-y) +PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) + +LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined \ + -nostdlib -z nodefaultlib +targets += purgatory.ro + +$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE + $(call if_changed,ld) + +targets += kexec_purgatory.c + +CMD_BIN2C = $(objtree)/scripts/basic/bin2c +quiet_cmd_bin2c = BIN2C $@ + cmd_bin2c = $(CMD_BIN2C) kexec_purgatory < $< > $@ + +$(obj)/kexec_purgatory.c: $(obj)/purgatory.ro FORCE + $(call if_changed,bin2c) + +obj-${CONFIG_KEXEC_FILE} += kexec_purgatory.o diff --git a/arch/arm64/purgatory/entry.S b/arch/arm64/purgatory/entry.S new file mode 100644 index 000000000000..fe6e968076db --- /dev/null +++ b/arch/arm64/purgatory/entry.S @@ -0,0 +1,55 @@ +/* + * kexec core purgatory + */ +#include +#include + +#define SHA256_DIGEST_SIZE 32 /* defined in crypto/sha.h */ + +.text + +ENTRY(purgatory_start) + /* Start new image. */ + ldr x17, __kernel_entry + ldr x0, __dtb_addr + mov x1, xzr + mov x2, xzr + mov x3, xzr + br x17 +END(purgatory_start) + +/* + * data section: + * kernel_entry and dtb_addr are global but also labelled as local, + * "__xxx:", to avoid unwanted re-linking. + * + * purgatory_sha_regions and purgatory_sha256_digest are referenced + * by kexec generic code and so must exist, but not actually used + * here because hash check is not that useful in purgatory. + */ +.align 3 + +.globl kernel_entry +kernel_entry: +__kernel_entry: + .quad 0 +END(kernel_entry) + +.globl dtb_addr +dtb_addr: +__dtb_addr: + .quad 0 +END(dtb_addr) + +.globl purgatory_sha_regions +purgatory_sha_regions: + .rept KEXEC_SEGMENT_MAX + .quad 0 + .quad 0 + .endr +END(purgatory_sha_regions) + +.globl purgatory_sha256_digest +purgatory_sha256_digest: + .skip SHA256_DIGEST_SIZE +END(purgatory_sha256_digest) From patchwork Fri Sep 15 10:59:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112717 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp471128qgf; Fri, 15 Sep 2017 03:58:40 -0700 (PDT) X-Received: by 10.98.66.207 with SMTP id h76mr24226557pfd.116.1505473120293; Fri, 15 Sep 2017 03:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473120; cv=none; d=google.com; s=arc-20160816; b=LXeu/9Z/xTYkLodORuvTzXApq+zK7f5JIAF7jjeixert8OPA58rpywj3Ns3UkxeE2v 0GLO6ks0Y72Jlu0XHUmAZv2hHG2y4ytyQke2KRGsx3Frw7tKOf6wImhdIoTR/K9StepR FZj247QEdthKsPv7Uf5emgrCcGL1fVI5/oouysEQv6i0Uj9GF/OnETSFBt4wWuSSUl+r i6O8b0eTA8kSaNBnbr1tkxtUz2pLZDeDn6fFOLlu3LY5ZzFv7UA0MYx3+mKDmLGzxKmz qyy4rZ13Sh5fjmkt81TsfquusDjr2KDKz16t1zz0dXYZNYEcctHLWJzTX0OIHzk7q7MD /z9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=RekydthaLF4mOInaau6pBRbOLvWFWNFYGuAUEaBMf6o=; b=RKdfwXilzKYylYIomUSlr/YTM7wI+Yv7aC9fLQCCx/THdy4VuPsZN0t7Ncu3epPdFr HUG7Kd5FIOGqjNMlgBSTK7CG0ThlIDnPmApGRPviA2tdqmpfNnygPSpmzOxJ69yFNlJq QX5+7xXlLXQ3gWZpXxpvK5G/I3/f1rQqeiPbUjhJh7d9VE9iWH1DUly+980vCed/Rjuf Wm5tU0EhVNQu3B9GQiCfWnaXGmSMZy4SB239efI/h7V1HlBEmU47XPBPps4I6qeCyFsG krfSddBG0Op7nwMMBDIt/VTaOgWe3XjDb6fgs+XCRLDLABTapsXvpaRmGUmD74kxOmLZ t0aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Je28yIvX; 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 f61si525910plb.25.2017.09.15.03.58.39; Fri, 15 Sep 2017 03:58:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Je28yIvX; 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 S1751685AbdIOK6f (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:35 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:48657 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751619AbdIOK6b (ORCPT ); Fri, 15 Sep 2017 06:58:31 -0400 Received: by mail-pf0-f177.google.com with SMTP id n24so1261366pfk.5 for ; Fri, 15 Sep 2017 03:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RekydthaLF4mOInaau6pBRbOLvWFWNFYGuAUEaBMf6o=; b=Je28yIvXIWTcN19idmBcjiBsEb372S3PczCll3Ns526b/IAnlEv4E+ACfYDbezPVIt 5cVXk9xZ6E0avB57yVwLMeaR/taZCsgeVoDDwq2j09890z/npmG8t1vYEBT2M4YBHfsu +cecE6tfAplaj+mDC+KRO073+cL5MNL1aGGLo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RekydthaLF4mOInaau6pBRbOLvWFWNFYGuAUEaBMf6o=; b=Yv4hienmuBXLAZnZc+UluzGiZQCa2LtaF5evKTHtauXJASaz69SxltcpyFtiNI1wLU P5fpF43iK3khnj12euJ/8SUICkmfEk14m87PWHOTw+Hd/zmCb12HuXgN93GX9BZkpVeb EfYmAx8SVasin5UgZWaXk+nPgoHjZAu1l2k3411nw3NzzDRbna+ocp/b//oTo580Um8d D+ItvERT8K6AYIWBpDTsUyHmasH9l7ai4oJSP6DH1Ev3benHSseo7JLtQ/zEahGjhn67 qXb/R0emjiW4yHkc1z0FjPRW675wKExShFKtXGKvs7znZ1aJ5uDIaTSuablBDYTlWXs8 Hs/g== X-Gm-Message-State: AHPjjUhhaCR7EtcBstxG0i2FWgxAYtjTx5HXthhlbbVaRm5NCIAfG3fD D/H149JW6+zrvdXU X-Google-Smtp-Source: ADKCNb6NNCxVQDzXq82QDtXOOla4sgN+8Z0oBj2U4gF1QTsA5iJZyRmGEGxxxzio5cEB2gocIcQdGw== X-Received: by 10.84.129.226 with SMTP id b89mr27119733plb.0.1505473110437; Fri, 15 Sep 2017 03:58:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v10sm1919168pgf.8.2017.09.15.03.58.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:28 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 07/10] arm64: kexec_file: load initrd, device-tree and purgatory segments Date: Fri, 15 Sep 2017 19:59:29 +0900 Message-Id: <20170915105932.25338-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org load_other_segments() sets up and adds all the memory segments necessary other than kernel, including initrd, device-tree blob and purgatory. Most of the code was borrowed from kexec-tools' counterpart. arch_kimage_kernel_post_load_cleanup() is meant to free arm64-specific data allocated for loading kernel. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/kexec.h | 22 ++++ arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/machine_kexec_file.c | 213 +++++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/machine_kexec_file.c -- 2.14.1 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..2fadd3cbf3af 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,28 @@ static inline void crash_prepare_suspend(void) {} static inline void crash_post_resume(void) {} #endif +#ifdef CONFIG_KEXEC_FILE +#define ARCH_HAS_KIMAGE_ARCH + +struct kimage_arch { + void *dtb_buf; +}; + +struct kimage; + +#define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup +extern int arch_kimage_file_post_load_cleanup(struct kimage *image); + +extern int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + char **dtb_buf, size_t *dtb_buf_len); +extern int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index f2b4e816b6de..5df003d6157c 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -48,8 +48,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..09be2674c2ab --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,213 @@ +/* + * kexec_file for arm64 + * + * Copyright (C) 2017 Linaro Limited + * Author: AKASHI Takahiro + * + * Most code is derived from arm64 port of kexec-tools + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include +#include +#include +#include +#include +#include + +static int __dt_root_addr_cells; +static int __dt_root_size_cells; + +struct kexec_file_ops *kexec_file_loaders[] = { + NULL +}; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb_buf); + image->arch.dtb_buf = NULL; + + return kexec_kernel_post_load_cleanup(image); +} + +int arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *)) +{ + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return walk_iomem_res_desc(crashk_res.desc, + IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, + crashk_res.start, crashk_res.end, + kbuf, func); + else if (kbuf->top_down) + return walk_system_ram_res_rev(0, ULONG_MAX, kbuf, func); + else + return walk_system_ram_res(0, ULONG_MAX, kbuf, func); +} + +int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + char **dtb_buf, size_t *dtb_buf_len) +{ + char *buf = NULL; + size_t buf_size; + int nodeoffset; + u64 value; + int range_len; + int ret; + + /* duplicate dt blob */ + buf_size = fdt_totalsize(initial_boot_params); + range_len = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + + if (initrd_load_addr) + buf_size += fdt_prop_len("initrd-start", sizeof(u64)) + + fdt_prop_len("initrd-end", sizeof(u64)); + + if (cmdline) + buf_size += fdt_prop_len("bootargs", cmdline_len + 1); + + buf = vmalloc(buf_size); + if (!buf) { + ret = -ENOMEM; + goto out_err; + } + + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) + goto out_err; + + nodeoffset = fdt_path_offset(buf, "/chosen"); + if (nodeoffset < 0) + goto out_err; + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop(buf, nodeoffset, "bootargs", + cmdline, cmdline_len + 1); + if (ret) + goto out_err; + } + + /* add initrd-* */ + if (initrd_load_addr) { + value = cpu_to_fdt64(initrd_load_addr); + ret = fdt_setprop(buf, nodeoffset, "initrd-start", + &value, sizeof(value)); + if (ret) + goto out_err; + + value = cpu_to_fdt64(initrd_load_addr + initrd_len); + ret = fdt_setprop(buf, nodeoffset, "initrd-end", + &value, sizeof(value)); + if (ret) + goto out_err; + } + + /* trim a buffer */ + fdt_pack(buf); + *dtb_buf = buf; + *dtb_buf_len = fdt_totalsize(buf); + + return 0; + +out_err: + vfree(buf); + return ret; +} + +int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + unsigned long initrd_load_addr = 0; + unsigned long purgatory_load_addr, dtb_load_addr; + char *dtb = NULL; + unsigned long dtb_len; + int ret = 0; + + kbuf.image = image; + /* not allocate anything below the kernel */ + kbuf.buf_min = kernel_load_addr; + + /* Load initrd */ + if (initrd) { + kbuf.buffer = initrd; + kbuf.bufsz = initrd_len; + kbuf.memsz = initrd_len; + kbuf.buf_align = PAGE_SIZE; + /* within 1GB-aligned window of up to 32GB in size */ + kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + + (unsigned long)SZ_1G * 31; + kbuf.top_down = 0; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + initrd_load_addr = kbuf.mem; + + pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + initrd_load_addr, initrd_len, initrd_len); + } + + /* Load dtb blob */ + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, cmdline_len, &dtb, &dtb_len); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + kbuf.buffer = dtb; + kbuf.bufsz = dtb_len; + kbuf.memsz = dtb_len; + /* not across 2MB boundary */ + kbuf.buf_align = SZ_2M; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = 1; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + dtb_load_addr = kbuf.mem; + image->arch.dtb_buf = dtb; + + pr_debug("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + dtb_load_addr, dtb_len, dtb_len); + + /* Load purgatory */ + ret = kexec_load_purgatory(image, kernel_load_addr, ULONG_MAX, 1, + &purgatory_load_addr); + if (ret) { + pr_err("Loading purgatory failed\n"); + goto out_err; + } + + ret = kexec_purgatory_get_set_symbol(image, "kernel_entry", + &kernel_load_addr, sizeof(kernel_load_addr), 0); + if (ret) { + pr_err("Setting symbol (kernel_entry) failed.\n"); + goto out_err; + } + + ret = kexec_purgatory_get_set_symbol(image, "dtb_addr", + &dtb_load_addr, sizeof(dtb_load_addr), 0); + if (ret) { + pr_err("Setting symbol (dtb_addr) failed.\n"); + goto out_err; + } + + pr_debug("Loaded purgatory at 0x%lx\n", purgatory_load_addr); + + return 0; + +out_err: + vfree(dtb); + image->arch.dtb_buf = NULL; + return ret; +} From patchwork Fri Sep 15 10:59:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112718 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp471163qgf; Fri, 15 Sep 2017 03:58:42 -0700 (PDT) X-Received: by 10.98.61.156 with SMTP id x28mr24266798pfj.295.1505473122582; Fri, 15 Sep 2017 03:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473122; cv=none; d=google.com; s=arc-20160816; b=0J7XY8E9bLDj/0Gjf9802ATeAVs6iZeTso3sR2DH1P5/WQTwxjXIgvcwPJoJQXLIhi HOKaEhE/tm2R8Imjn9stji6M8yhaYVTpo6GmpsH9hbhHlir/lYwiBe6H/Fw+Ply+VgeJ rn87F8uXsiPlED3bZ5lrnch4YwjYLRIz3GLBWCgOAxw+FDoWEwL2CNQ71nRrrOakK77W BvXyFkayuwfn1HmVltcnceDNvqku+JffPlTcT33t9Ietrd/EyLE9SVls1pxqMlTx0Clj Xb/vJMMBMWjQheyju3pFjETiqx7ZZ8fh9BDnWUTGRFXTgSNXUII5Ue57RE+7cWZJrEkF Fv0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vU3bJbVRQ6O+Bg7t4tZq2JCPlwk3UkAti/RfJLhOxQc=; b=dcE24Hqau4zTGOGT6wc3eybrQf646hcGWNAuczMgmkvnJxVFiqvrN01OwqnR456Ktf fNpHNJPiZ+NPq+JEQXF6a+rgOpLa9SnszHt5yaIZq+lU2fjJbiH/RNaDAcEt3hB4ekyA jq+a5tOC89D5RSL9xVDisC9yAGxFooQKr+V0Jh/ZJKfxVvKdeTweZ1VhuCmLeiWhtnfJ UFdgsNNAnzQT6Q1OovOdP413GZGpYNf+pUh1l8sFlMNBaUjTxic7tGj6UBKOm7/niagt A667/2tn4HIQ6V/1I3vC0nGUmadWYz78earNEFUgCaeWvXC+lflS0VnjbOXPIPOCXTej ciYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ewj3qusx; 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 f61si525910plb.25.2017.09.15.03.58.42; Fri, 15 Sep 2017 03:58:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ewj3qusx; 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 S1751722AbdIOK6i (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:38 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:53961 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751619AbdIOK6g (ORCPT ); Fri, 15 Sep 2017 06:58:36 -0400 Received: by mail-pg0-f45.google.com with SMTP id j70so1300336pgc.10 for ; Fri, 15 Sep 2017 03:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vU3bJbVRQ6O+Bg7t4tZq2JCPlwk3UkAti/RfJLhOxQc=; b=ewj3qusxnF7xwIVYUyfh3gW3yZJudIApnL9Zo7KdkOObEUJuJkE4mQ6pZlPlQ7c2QN jWVWadqe0tnqhwDDR6zmTFodU0UgycO1PFJ3vd3i0i5yUzXivgbj4wEVy9ITRHmHfm1Y /4bWCe5y4X4vJppt/SxRVyvTn6iSsINaSwc9Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vU3bJbVRQ6O+Bg7t4tZq2JCPlwk3UkAti/RfJLhOxQc=; b=eNsEENa22907wYBq0yE67vb7+SGSB/l5L5uvwM77JjO8Um8UO+MZ1/PTqVYarrDVnP EVWv7Aiovuufqpc8mkJLwSAh5qryFhM36bY5YUTIo1HJNlZcO2vo+Q8DOSzCLxHw9vgv TwCffFcZLtmHP2vetxjRSxy21cZyYGLy5BuiXcMBEN8ZAsHbrw3KrZWabTIxqEGFkznP RnQl6XKcEdR5N59/pzH60oAEBMS4cEqrdUq/BWMMJTlO1bZ5iOWmr5E1/B2YeYkH0qkD LkAX3FNKLpkSxFTxE90MGAmMBx1y/JDic61XY9Etpt7a55FXbKtbY+qhMrk2cnxUe5b6 N2aA== X-Gm-Message-State: AHPjjUhOf+Tu5MhPGe1/I42qx9ZD3FZM5aekKXJy9YVt/w19lANVT7nF xmfla4sKkNOWdG9P X-Google-Smtp-Source: ADKCNb5gbjGf9smjm6uOjuIsdlX/ojXxVswdiIVNoKew1L6GzOk4I5oVR9dvyDoEnpZ1Sql99DsYGw== X-Received: by 10.99.120.8 with SMTP id t8mr18075866pgc.122.1505473115750; Fri, 15 Sep 2017 03:58:35 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c85sm1896816pfj.118.2017.09.15.03.58.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:35 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 08/10] arm64: kexec_file: set up for crash dump adding elf core header Date: Fri, 15 Sep 2017 19:59:30 +0900 Message-Id: <20170915105932.25338-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org load_crashdump_segments() creates and loads a memory segment of elf core header for crash dump. "linux,usable-memory-range" and "linux,elfcorehdr" will add to the 2nd kernel's device-tree blob. The logic of this cod is also from kexec-tools. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/kexec.h | 5 ++ arch/arm64/kernel/machine_kexec_file.c | 149 +++++++++++++++++++++++++++++++++ kernel/kexec_file.c | 2 +- 3 files changed, 155 insertions(+), 1 deletion(-) -- 2.14.1 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 2fadd3cbf3af..edb702e64a8a 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -98,6 +98,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { void *dtb_buf; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_sz; + unsigned long elf_load_addr; }; struct kimage; @@ -113,6 +117,7 @@ extern int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, char *initrd, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len); +extern int load_crashdump_segments(struct kimage *image); #endif #endif /* __ASSEMBLY__ */ diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 09be2674c2ab..e4671610fb12 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -32,6 +32,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb_buf); image->arch.dtb_buf = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return kexec_kernel_post_load_cleanup(image); } @@ -48,6 +52,77 @@ int arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *)) return walk_system_ram_res(0, ULONG_MAX, kbuf, func); } +static int __init arch_kexec_file_init(void) +{ + /* Those values are used later on loading the kernel */ + __dt_root_addr_cells = dt_root_addr_cells; + __dt_root_size_cells = dt_root_size_cells; + + return 0; +} +late_initcall(arch_kexec_file_init); + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +static int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static bool cells_size_fitted(unsigned long base, unsigned long size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((__dt_root_addr_cells == 1) && (base >= (1ULL << 32))) + return false; + + if ((__dt_root_size_cells == 1) && (size >= (1ULL << 32))) + return false; + + return true; +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + u32 val32; + int i; + + if (cells == 1) { + val32 = cpu_to_fdt32((u32)val64); + memcpy(buf, &val32, sizeof(val32)); + } else { + for (i = 0; i < (cells * sizeof(u32) - sizeof(u64)); i++) + *(char *)buf++ = 0; + + val64 = cpu_to_fdt64(val64); + memcpy(buf, &val64, sizeof(val64)); + } +} + +static int fdt_setprop_range(void *fdt, int nodeoffset, const char *name, + unsigned long addr, unsigned long size) +{ + u64 range[2]; + void *prop; + size_t buf_size; + int result; + + prop = range; + buf_size = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + + fill_property(prop, addr, __dt_root_addr_cells); + prop += __dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, __dt_root_size_cells); + prop += __dt_root_size_cells * sizeof(u32); + + result = fdt_setprop(fdt, nodeoffset, name, range, buf_size); + + return result; +} + int setup_dtb(struct kimage *image, unsigned long initrd_load_addr, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len, @@ -60,10 +135,26 @@ int setup_dtb(struct kimage *image, int range_len; int ret; + /* check ranges against root's #address-cells and #size-cells */ + if (image->type == KEXEC_TYPE_CRASH && + (!cells_size_fitted(image->arch.elf_load_addr, + image->arch.elf_headers_sz) || + !cells_size_fitted(crashk_res.start, + crashk_res.end - crashk_res.start + 1))) { + pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n"); + ret = -EINVAL; + goto out_err; + } + /* duplicate dt blob */ buf_size = fdt_totalsize(initial_boot_params); range_len = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); + if (image->type == KEXEC_TYPE_CRASH) + buf_size += fdt_prop_len("linux,elfcorehdr", range_len) + + fdt_prop_len("linux,usable-memory-range", + range_len); + if (initrd_load_addr) buf_size += fdt_prop_len("initrd-start", sizeof(u64)) + fdt_prop_len("initrd-end", sizeof(u64)); @@ -85,6 +176,23 @@ int setup_dtb(struct kimage *image, if (nodeoffset < 0) goto out_err; + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_range(buf, nodeoffset, "linux,elfcorehdr", + image->arch.elf_load_addr, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_range(buf, nodeoffset, + "linux,usable-memory-range", + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop(buf, nodeoffset, "bootargs", @@ -211,3 +319,44 @@ int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, image->arch.dtb_buf = NULL; return ret; } + +int load_crashdump_segments(struct kimage *image) +{ + void *elf_addr; + unsigned long elf_sz; + struct kexec_buf kbuf; + int ret; + + if (image->type != KEXEC_TYPE_CRASH) + return 0; + + /* Prepare elf headers and add a segment */ + ret = prepare_elf_headers(image, &elf_addr, &elf_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + return ret; + } + + kbuf.image = image; + kbuf.buffer = elf_addr; + kbuf.bufsz = elf_sz; + kbuf.memsz = elf_sz; + kbuf.buf_align = PAGE_SIZE; + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + kbuf.top_down = 1; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(elf_addr); + return ret; + } + image->arch.elf_headers = elf_addr; + image->arch.elf_headers_sz = elf_sz; + image->arch.elf_load_addr = kbuf.mem; + + pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + image->arch.elf_load_addr, elf_sz, elf_sz); + + return ret; +} diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 6a0e31e175af..6b206883f429 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -1317,7 +1317,7 @@ static int prepare_elf64_headers(struct crash_elf_data *ced, phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE; (ehdr->e_phnum)++; -#ifdef CONFIG_X86_64 +#if defined(CONFIG_X86_64) || defined(CONFIG_ARM64) /* Prepare PT_LOAD type program header for kernel text region */ phdr = (Elf64_Phdr *)bufp; bufp += sizeof(Elf64_Phdr); From patchwork Fri Sep 15 10:59:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112719 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp471221qgf; Fri, 15 Sep 2017 03:58:46 -0700 (PDT) X-Received: by 10.84.199.170 with SMTP id r39mr27172402pld.375.1505473126651; Fri, 15 Sep 2017 03:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473126; cv=none; d=google.com; s=arc-20160816; b=UmoWa0YAbjr3QkFHk+8nOaXvtqj4HPBmXf8jVm7HRXpjKt0d58+HfnL7dY/6AbmdBp Gowv6F1nB3gr2rcVZL5kKk3jZQoVKMhMADuL5LO6EEnIzqG+AvWWVyoHWwdSRoveuM+8 uGvp2BXbscfTpEy6SQzaCLWCWzhcq60jGBaT5Ygu1z1y4NEsgxksO3MD69MoE9pLgmws IZedydhmUR8vXMxgVkEYAaXojgXmBC3QZnm/FUie9HDLLLsNBRpi40sbdp6byXoic6Np 3ERtgTDiWi4ileSNfs7TCsWEyz++ADUycKxogCh4dsJYODVOJBOr5wyhFtRxFvMapLPQ R6fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=6N1HRUBXR+9BAp84bModHeDJ1qralue1O2AZ+ahcyEA=; b=GU0S2nCszYtuZi29IdrqpPBGpXW5Ef+zq7NwrCQzkblyt1+4UZmqAhAU43Ro52uojB GgyZ2L17/0+7oX3X27izfZg/cZe8rFmzcsd7FpA/+9uEwpP8Of+YBBzK+6gBNKSHlL3m w63S/j61bP6s4U8WZAWUhXuf2hWN9nrQ+sZa689wv/lUwjQQ4mWjtvV0zQd2XPcL2/1v K2QJlpL6MT99o2oEkMJL2FU80aly+GCxFJLK+fYUElk+9Z0HWA4MLtgr+QmfNokOHfO6 k4E0qPMR1xoE554nTvh0pctkMvmVPFxMtu5psB0Gwyjd0hjfwZA4JRBBsCIqTRYXJEwj Wpjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H3nXgznr; 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 a9si475163pgf.107.2017.09.15.03.58.46; Fri, 15 Sep 2017 03:58:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H3nXgznr; 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 S1751753AbdIOK6n (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:43 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:55226 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751724AbdIOK6k (ORCPT ); Fri, 15 Sep 2017 06:58:40 -0400 Received: by mail-pf0-f177.google.com with SMTP id d187so1251384pfg.11 for ; Fri, 15 Sep 2017 03:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6N1HRUBXR+9BAp84bModHeDJ1qralue1O2AZ+ahcyEA=; b=H3nXgznrpY1BwgDjFxnDQU8wsyKODj1ZXkuwpiX2emspuMMPsEpFvgGie4n10CkcbW Wba3NshdCDkn6AULQsdx6eje+j0TSWhvSFpoccVWbZyTFj046xMCuVIgu2d2sy9h6p8r CmHPGgEdH9JmaXamN2Rff00DyR0VHmRnsICZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6N1HRUBXR+9BAp84bModHeDJ1qralue1O2AZ+ahcyEA=; b=G93GM1SUkjoRbU46+kZdVlYizfZ69R0/h5djqKXSepxMVV/upbGfzY3qI+/Z5aMbrn Lz8spf38OmlfN/oDwhgMMoZ25lu90zjHAvwnkzCTQRa9IopW2qp0bJRDGvRzn7rpUERn shiZewKmAY+KUAbGs216SRqn/44fKNq3LEdk7hF60btuuXE3qwDFV15XTpLoyLWN1+1k us+jO7JV5GQNV0Jw01jfr13v0iH58Utg3Bong+umRqKkqAO3+QR/UtdYPxN7Tn+tB4Vv Nh7kK7atAVTvLDffK7ep2nNqO5wMkOlQo8uShdYzutUQ1RKTs4yj+CNUTfDN3U+cQOiH 6Ziw== X-Gm-Message-State: AHPjjUhcjoQQyuvJeD6tcURqnNOznolBK2ka3KhBM2rMCZn6kLvlukd4 VVXP3RbzNAzYWq5P X-Google-Smtp-Source: ADKCNb4hDRLE4dSTNyY2SM+lKfEcOlQgK3WC/l3sVy5FMTEM1Pb7XgR3IIK6NZeRckSFoXZHccAZVw== X-Received: by 10.99.115.30 with SMTP id o30mr24635942pgc.447.1505473120018; Fri, 15 Sep 2017 03:58:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o30sm1706852pgc.83.2017.09.15.03.58.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:39 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 09/10] arm64: enable KEXEC_FILE config Date: Fri, 15 Sep 2017 19:59:31 +0900 Message-Id: <20170915105932.25338-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Modify arm64/Kconfig and Makefile to enable kexec_file_load support. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Kconfig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) -- 2.14.1 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index dfd908630631..fa7299f08cc6 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -756,6 +756,28 @@ config KEXEC but it is independent of the system firmware. And like a reboot you can start any kernel with it, not just Linux. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + select BUILD_BIN2C + ---help--- + This is new version of kexec system call. This system call is + file based and takes file descriptors as system call argument + for kernel and initramfs as opposed to list of segments as + accepted by previous system call. + + In addition to this option, you need to enable a specific type + of image support. + +config KEXEC_VERIFY_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE + select SYSTEM_DATA_VERIFICATION + ---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. + config CRASH_DUMP bool "Build kdump crash kernel" help From patchwork Fri Sep 15 10:59:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 112720 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp471285qgf; Fri, 15 Sep 2017 03:58:52 -0700 (PDT) X-Received: by 10.98.245.74 with SMTP id n71mr24544266pfh.102.1505473132341; Fri, 15 Sep 2017 03:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473132; cv=none; d=google.com; s=arc-20160816; b=uDylnD4TCZxJJUN0c33dkcvG/zKF8n/SlmM7pZ17QjU6EwmeNPbzpYW7L6CFC3K7oO Pq8ortDXpCCi/gS0yxEVDh3ihjbETWSabShI587ppBdEt88W1m2E8G6JMKDTmFPoYeNL x7cq/bCOSVvg1KqBq9W3B+6yDO91xXNMREQd/5wLIIuy01bT7+s+6YJugpNqHZILrrLi fvvrcL5EriynVTyGXrUwIEYc4SQtXSa0xrnO9lflGNg7yFoKza1SgLhp7T9v9KIKYIg0 j8b/qrM/VfQozP+9kOFyi80thznDkwT26uJe7YR2jiv6wTJzZE8pusbMv4K1CcT2wCCl 1boA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=tyP5JW0dzRyK515B3yNh7AEA1TDu0Z2oXB012JSaGkM=; b=HSXmDUabVh3QSMfVstyxqcmBe8/qYXk+r2PgQ68wrdWrLzI/73l7FImH3KaXJFKKYD utxI69+TmwnbfiHiuCHGPfjS/KBKuvuTwcVzmg7HKGS86zxmLLjlXQX0ws6kTGySPja3 4430hbCxlW7zBQI61iyv5DWy765tXFlDoT0e4YpCCTL3yq5zQyfBRPAClx5/yH2blrLZ HLZBOl/+R8SRIFRFHWEHdEoJh7s1wd+wVudW4gU0qjCD/587NlqWFihLPpwEOS+3SpPR jU4uBk7NT9Tf9jQhmUkGM0EyijyqQKJzD0kpLaCTwbWMUHfZPgueVNZu2kQ9O+/t4B/r bA/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O4C/4ZMn; 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 a9si475163pgf.107.2017.09.15.03.58.51; Fri, 15 Sep 2017 03:58:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O4C/4ZMn; 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 S1751795AbdIOK6t (ORCPT + 26 others); Fri, 15 Sep 2017 06:58:49 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:49830 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751758AbdIOK6p (ORCPT ); Fri, 15 Sep 2017 06:58:45 -0400 Received: by mail-pf0-f176.google.com with SMTP id l188so1256327pfc.6 for ; Fri, 15 Sep 2017 03:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tyP5JW0dzRyK515B3yNh7AEA1TDu0Z2oXB012JSaGkM=; b=O4C/4ZMnEIodlgxdf3zAgFV+GvsiZWqGyvTEa2wuciLr+7vDI6cLkXIs1rn8uTRC2N wXJS7ua3FVfmc1B4dKveF0VMy2PdCbn3CrW+sVBTsxsMkUd9gT9HEnkuBCBx+J31ksJ2 2YLTjrsF/nvhn06ryPTedCsiDkvnq+BqtS6qA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tyP5JW0dzRyK515B3yNh7AEA1TDu0Z2oXB012JSaGkM=; b=Vm+6HgjvXzhMjDzxghIqYGdCgdLJxVEy0z56DvpEUPlTF9PJVdwl73GW9ODNcmh9sd 0utgaRiPYOJAtduqyxte0fU30m2dQPatwo6NLxuthFv72bhK6eBwLFb9qPLYl6ET0H/h jzbRU7KFVSBKFAigLF0aQAjyhKGWBnJGWNrFQxo1pIfxVCbud4EU6dtuxn2q7IhdE5sJ yk+qODpICnnyZtYhKLc5l2ZvHzni9lz9yq1NOvsPV9mFgpP8LiqvaYT0aaP5BKBvCmm3 WavVoNhoB7re9BNr18gps7SyPPurBjFc0pXuZB5jXLXOEjpjtEvKTbI3N6lDDLbmS1XP BQjQ== X-Gm-Message-State: AHPjjUhtsXVTB8jFMYJv/9A3IQDAgx4DI3krRgaMMIh8AkVLOehjxlG4 DGBColGM1u+uRcmZ X-Google-Smtp-Source: ADKCNb5m0GqTByqV3J2qUH51l278Lpv3wMo6Q4lfmorwKqil+YWVkV9WBVbk0BVqg9Nt03u9iGbdXQ== X-Received: by 10.99.96.69 with SMTP id u66mr23665743pgb.337.1505473124851; Fri, 15 Sep 2017 03:58:44 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s62sm1941112pfe.91.2017.09.15.03.58.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:58:44 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v3 10/10] arm64: kexec_file: add Image format support Date: Fri, 15 Sep 2017 19:59:32 +0900 Message-Id: <20170915105932.25338-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170915105932.25338-1-takahiro.akashi@linaro.org> References: <20170915105932.25338-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "Image" binary will be loaded at the offset of TEXT_OFFSET from the start of system memory. TEXT_OFFSET is determined from the header of the image. Regarding kernel signature verification, it will be done through verify_pefile_signature() as arm64's "Image" binary can be seen as in PE format. This approach is consistent with x86 implementation. we can sign an image with sbsign command. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Kconfig | 7 +++ arch/arm64/include/asm/kexec.h | 66 +++++++++++++++++++++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/kexec_image.c | 105 +++++++++++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 3 + 5 files changed, 182 insertions(+) create mode 100644 arch/arm64/kernel/kexec_image.c -- 2.14.1 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index fa7299f08cc6..b7f1a760434a 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -769,10 +769,17 @@ config KEXEC_FILE In addition to this option, you need to enable a specific type of image support. +config KEXEC_FILE_IMAGE_FMT + bool "Enable Image support" + depends on KEXEC_FILE + ---help--- + Select this option to enable 'Image' kernel loading. + config KEXEC_VERIFY_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE select SYSTEM_DATA_VERIFICATION + select SIGNED_PE_FILE_VERIFICATION if KEXEC_FILE_IMAGE_FMT ---help--- Select this option to verify a signature with loaded kernel image. If configured, any attempt of loading a image without diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index edb702e64a8a..7ec529e11a8b 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -104,6 +104,72 @@ struct kimage_arch { unsigned long elf_load_addr; }; +/** + * struct arm64_image_header - arm64 kernel image header + * + * @pe_sig: Optional PE format 'MZ' signature + * @branch_code: Instruction to branch to stext + * @text_offset: Image load offset, little endian + * @image_size: Effective image size, little endian + * @flags: + * Bit 0: Kernel endianness. 0=little endian, 1=big endian + * @reserved: Reserved + * @magic: Magic number, "ARM\x64" + * @pe_header: Optional offset to a PE format header + **/ + +struct arm64_image_header { + u8 pe_sig[2]; + u8 pad[2]; + u32 branch_code; + u64 text_offset; + u64 image_size; + u64 flags; + u64 reserved[3]; + u8 magic[4]; + u32 pe_header; +}; + +static const u8 arm64_image_magic[4] = {'A', 'R', 'M', 0x64U}; +static const u8 arm64_image_pe_sig[2] = {'M', 'Z'}; + +/** + * arm64_header_check_magic - Helper to check the arm64 image header. + * + * Returns non-zero if header is OK. + */ + +static inline int arm64_header_check_magic(const struct arm64_image_header *h) +{ + if (!h) + return 0; + + if (!h->text_offset) + return 0; + + return (h->magic[0] == arm64_image_magic[0] + && h->magic[1] == arm64_image_magic[1] + && h->magic[2] == arm64_image_magic[2] + && h->magic[3] == arm64_image_magic[3]); +} + +/** + * arm64_header_check_pe_sig - Helper to check the arm64 image header. + * + * Returns non-zero if 'MZ' signature is found. + */ + +static inline int arm64_header_check_pe_sig(const struct arm64_image_header *h) +{ + if (!h) + return 0; + + return (h->pe_sig[0] == arm64_image_pe_sig[0] + && h->pe_sig[1] == arm64_image_pe_sig[1]); +} + +extern struct kexec_file_ops kexec_image_ops; + struct kimage; #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 5df003d6157c..a1161bab6810 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -51,6 +51,7 @@ 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_IMAGE_FMT) += 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..b19538af2f3d --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,105 @@ +/* + * Kexec image loader + + * Copyright (C) 2017 Linaro Limited + * Author: AKASHI Takahiro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) "kexec_file(Image): " fmt + +#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 ((kernel_len < sizeof(*h)) || !arm64_header_check_magic(h)) + return -EINVAL; + + pr_debug("PE format: %s\n", + (arm64_header_check_pe_sig(h) ? "yes" : "no")); + + return 0; +} + +static void *image_load(struct kimage *image, char *kernel, + unsigned long kernel_len, char *initrd, + unsigned long initrd_len, char *cmdline, + unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + struct arm64_image_header *h = (struct arm64_image_header *)kernel; + unsigned long text_offset, kernel_load_addr; + int ret; + + /* Create elf core header segment */ + ret = load_crashdump_segments(image); + if (ret) + goto out; + + /* Load the kernel */ + kbuf.image = image; + if (image->type == KEXEC_TYPE_CRASH) { + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + } else { + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + } + kbuf.top_down = 0; + + kbuf.buffer = kernel; + kbuf.bufsz = kernel_len; + kbuf.memsz = le64_to_cpu(h->image_size); + text_offset = le64_to_cpu(h->text_offset); + kbuf.buf_align = SZ_2M; + + /* Adjust kernel segment with TEXT_OFFSET */ + kbuf.memsz += text_offset; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out; + + image->segment[image->nr_segments - 1].mem += text_offset; + image->segment[image->nr_segments - 1].memsz -= text_offset; + kernel_load_addr = kbuf.mem + text_offset; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kernel_load_addr, kbuf.bufsz, kbuf.memsz); + + /* Load additional data */ + ret = load_other_segments(image, kernel_load_addr, + initrd, initrd_len, cmdline, cmdline_len); + +out: + return ERR_PTR(ret); +} + +#ifdef CONFIG_KEXEC_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 + +struct kexec_file_ops kexec_image_ops = { + .probe = image_probe, + .load = image_load, +#ifdef CONFIG_KEXEC_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif +}; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index e4671610fb12..fbf1cb4b58df 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -24,6 +24,9 @@ static int __dt_root_addr_cells; static int __dt_root_size_cells; struct kexec_file_ops *kexec_file_loaders[] = { +#ifdef CONFIG_KEXEC_FILE_IMAGE_FMT + &kexec_image_ops, +#endif NULL };