From patchwork Wed Jul 11 07:41:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141667 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4799382ljj; Wed, 11 Jul 2018 00:41:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcvqziKTw+VAzn/3xKqOV7wRAr0dSIn7M4TURQjk6DTS/FkjLUETkWa4b3iNlDUJypaYUx6 X-Received: by 2002:a17:902:bc49:: with SMTP id t9-v6mr27580377plz.116.1531294883956; Wed, 11 Jul 2018 00:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294883; cv=none; d=google.com; s=arc-20160816; b=n0lrGonGasvcqAC2vtSO0F7e0qGcRQaEdo7uNfYHQ3py+L+OAo3JaMg1bb68DxAeaW 7MuxTyQmEDlN+gCq/aVXv7fpH8kFqmsXvfEwaf0M22zAPUDiIVsX4Mt6+7G7dBZc+rXc mGz3EMB+bpHC06Z6gaOUfsNNSTgngQ5U11Orovhptql+4WitD+TrxBv6YjDKcuMzgvc5 h+TUhAaY1RPOhYVcd5PYbj/Rw+45zlLAZim4odxCgU/R+Wu1cVOCYJWmuE2u5v8pWM5c bhx2voG8g4iiefkGPdI1XGzu0HJc2RS50HObYd8CRLFgIUb489CRTXCNc+IvRktaKuSU VE0w== 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=jdv7JCAGldq0YAFu/ACWfRReGIBSUaIhom0oFCx/M8A=; b=EAdXCKjRXumZ38vOal3VbFMZ8SnjUwYul4WEq/LLWCD17MMLrIwOcFvfJZhohgmhhh 1p1WRvrmh8rTVah7uCHn5yoalkVQNwGKiUTRiiMFvG3bynoEyOWZSartSv2ZRxUCGqWu /vp9r3ECDe9F2k3lmSf0Cg1J2gRDyryN0tR3OSVMmzcxZRTt9jGerzIbbE7aoR3O1pPF jc+DxtofpZAc8tjsk+WULWeolpzjbM6+jRUYPQ50gUWi0SJscng2vZTRTnE0VeodirQ4 ZxTnOEjb+wr6c1lP1q8GZBeJ/17IlUU2GUos0rcCznDb0Tvbd2R+0ddapSjnwA4AiaTf zFBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dm5oxzfS; 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 1-v6si18563164plx.227.2018.07.11.00.41.23; Wed, 11 Jul 2018 00:41:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dm5oxzfS; 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 S1726492AbeGKHoR (ORCPT + 22 others); Wed, 11 Jul 2018 03:44:17 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:38731 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeGKHoQ (ORCPT ); Wed, 11 Jul 2018 03:44:16 -0400 Received: by mail-pf0-f196.google.com with SMTP id x13-v6so7934943pfh.5 for ; Wed, 11 Jul 2018 00:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jdv7JCAGldq0YAFu/ACWfRReGIBSUaIhom0oFCx/M8A=; b=Dm5oxzfS/VL+fy39Xpvjev3g4m24EgwtLdK2HE8U1ISXZ4k+MOZO3CAprlZTLbwZiH GVJ3ghPMkxTO2RrXqNLJQ8n7e/CIU8mH+X+bRwbpgnhZk1lRlRS8fQn+Z5hUp3tXXBUT fR9D8VZKtc23trnO6nlTXLwsO4iXFO+zlek3Y= 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=jdv7JCAGldq0YAFu/ACWfRReGIBSUaIhom0oFCx/M8A=; b=KuMxMzBCQkUpGtQo0hSn5hZVBF/I8UPGZCGiQ/oQEMN0suP+31SpoL6BmjudXhZaHn nnZKfCkpNLgPbYNg+xCZjK/uwzpIJWbnJT9gtoIvImTMdHpA8SDNrZU+PYI/sLmlWUIS SM+R7RMdcgSJ97VoOtF6mljCsEpAK+iG2TggWFv4UYkdM9Sg1MGPbnVQMofDR2vwyO3P 7rFc+9ZSKo2bidQAgM18v7QUtbl5kJ0LpJMyI3mpjbQvBLA0unyLUx7X4LCBPJi+bmIE VVHxPrJsfA9aILbPa4mUYfKZ1qQx3QeqXgGoi4qimz45UT69XTq0BkL1fPisBU4nog2Q knZw== X-Gm-Message-State: APt69E0iCPK17VZBcJagUlAPRFyJouVpSzC/cVva7yRyduer7GMRp+Wo 2tpvCTPkUnIvJVELzsQKJ0GQGg== X-Received: by 2002:a62:b0c:: with SMTP id t12-v6mr6185257pfi.36.1531294880962; Wed, 11 Jul 2018 00:41:20 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f10-v6sm33866590pgr.30.2018.07.11.00.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:41:20 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 01/15] asm-generic: add kexec_file_load system call to unistd.h Date: Wed, 11 Jul 2018 16:41:49 +0900 Message-Id: <20180711074203.3019-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-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.17.0 diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 42990676a55e..c81f4a0df51f 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -734,9 +734,11 @@ __SYSCALL(__NR_pkey_free, sys_pkey_free) __SYSCALL(__NR_statx, sys_statx) #define __NR_io_pgetevents 292 __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents) +#define __NR_kexec_file_load 293 +__SYSCALL(__NR_kexec_file_load, sys_kexec_file_load) #undef __NR_syscalls -#define __NR_syscalls 293 +#define __NR_syscalls 294 /* * 32 bit systems traditionally used different From patchwork Wed Jul 11 07:41:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141668 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4799526ljj; Wed, 11 Jul 2018 00:41:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc8PgDMGQOqpSpVz8qUWz0VnwXhL3s8nm68rp9uceo8eGSWHyYiM5q2cbDgAIyYBhFPqDac X-Received: by 2002:a17:902:8:: with SMTP id 8-v6mr28331376pla.287.1531294894850; Wed, 11 Jul 2018 00:41:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294894; cv=none; d=google.com; s=arc-20160816; b=bmG0t3wifTxqTis+zMDKsKMChAwEkt48MrxC8nvB3dd7XTL8jcHga8l0Gs63sINPaH Oji/HAS/kqMKuTuzx/z7Z4GtkDXBYrlXt7nGVjgelB9Zffs5TX+/2STXDvgBuV07+wEG RE/7G65wqQJNeGF9x/Wv9Q5NgXLUTtN0cgus5Tv2WKoxaVBDTBd/V9rUqkcCNwqy3KXu iNsBwsM5dE9Dj5/GivUGodupDgiY8cCdjlofLYKs6rsCrrNkB5Ii6OoDptTHHHJYqCOA K/NLB6idAi36polG+npHy8jQdVQZ/smfTnW4cjZG4ttiE4ORZimpqXJzBz6ktODkhQr4 6Mhw== 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=+CuyitM4U+PQMgPnwkmGxBBf2FkG58yPNy8pZ5fB6pc=; b=wOo2r+w75cNRQBuVpyosllweiUH7/8DDkicr07eDA4YEN3A7axCiNoV+4jGfp9cyeS V0vZ8gx04+P6dRyZrVNit5HORBlSaN+jq1lg0NTHotydcgH6zkvEMSavr9zzvGPySu0t PHnfMwoBamJCcQbI69LHoubmt3hdkq+FvQXWw3DtVEIIVhk2v6IEjn2r+eskxjWP++uU +U7EoHRnjzr5oDD1pk75c0Ri+yiBUoTGz9BB3L6FBMG865sZ0bbjqoFBuluk/wT/gRfO hZl1GdF62K6d8i/pno2+n0ar+W3iFl2XSxlUHFcYfROl9rFY5DyCsq++W2ULM2K9flNf ZGVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HRWt8TQ3; 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 y12-v6si15889174plt.302.2018.07.11.00.41.34; Wed, 11 Jul 2018 00:41:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HRWt8TQ3; 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 S1726538AbeGKHo1 (ORCPT + 22 others); Wed, 11 Jul 2018 03:44:27 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:43067 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726495AbeGKHo1 (ORCPT ); Wed, 11 Jul 2018 03:44:27 -0400 Received: by mail-pf0-f170.google.com with SMTP id y8-v6so17862471pfm.10 for ; Wed, 11 Jul 2018 00:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+CuyitM4U+PQMgPnwkmGxBBf2FkG58yPNy8pZ5fB6pc=; b=HRWt8TQ3Cl6oR0kcTXEgGxozpWcG8baNcKuE3hUjeWekTYbX/K612I9/00RKjjn/nt w48krRd3k5N/YCrjzCEWqZREhCx/lVfmhLWttOU9Ot0b/XAXa7Ji7lVc7DsPWeX/7XA1 zJrrsE5i6W+57sRp/SRgUED9kq1NfsPaMIu8U= 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=+CuyitM4U+PQMgPnwkmGxBBf2FkG58yPNy8pZ5fB6pc=; b=V70Bg6lUrI58lndezp39hvsn1iJGCKM4MEjf6lU34x0cZByy5RQ7cMfrQpClAXI75E ECOFcC4p47MEaR1v8NAEYW4vIaF9YOnLEmHaLUkTVOLgeHBXmhwHbQOc+V5uqXiIAgzw 9SkHMOfCVwQ+gBQeEYBeyDDbncxL/fla4RgEYLpyV1PaNB1eRjb1oaFAWWCsm5Oc1+Jh ioK3/U/XhvuJVCrSV0fu4h5A29bcX/ScypMNHawr6NMvyy1Bn3S/9UF8+5qO4IQOjJ+L 4e/G+z7/ZDqhAs2O73/DtY3ctXqfjojTivUVB8Zh9SD3KhD7xwarCDVtNb3AKN2E3HZ1 onHg== X-Gm-Message-State: APt69E3qr2WYZBZa3R09UIgPZHBQFvYXbS9TUhFtIZi7W6ZcnqECRP+H n96DRxVRQPRcbe0D/uTPdcq5/g== X-Received: by 2002:a63:4e5f:: with SMTP id o31-v6mr23988056pgl.256.1531294891841; Wed, 11 Jul 2018 00:41:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a191-v6sm4362266pge.45.2018.07.11.00.41.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:41:31 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 02/15] kexec_file: make kexec_image_post_load_cleanup_default() global Date: Wed, 11 Jul 2018 16:41:50 +0900 Message-Id: <20180711074203.3019-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Change this function from static to global so that arm64 can implement its own arch_kimage_file_post_load_cleanup() later using kexec_image_post_load_cleanup_default(). Signed-off-by: AKASHI Takahiro Acked-by: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- include/linux/kexec.h | 1 + kernel/kexec_file.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) -- 2.17.0 diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 9e4e638fb505..49ab758f4d91 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -143,6 +143,7 @@ extern const struct kexec_file_ops * const kexec_file_loaders[]; int kexec_image_probe_default(struct kimage *image, void *buf, unsigned long buf_len); +int kexec_image_post_load_cleanup_default(struct kimage *image); /** * struct kexec_buf - parameters for finding a place for a buffer in memory diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index c6a3b6851372..63c7ce1c0c3e 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -78,7 +78,7 @@ void * __weak arch_kexec_kernel_image_load(struct kimage *image) return kexec_image_load_default(image); } -static int kexec_image_post_load_cleanup_default(struct kimage *image) +int kexec_image_post_load_cleanup_default(struct kimage *image) { if (!image->fops || !image->fops->cleanup) return 0; From patchwork Wed Jul 11 07:41:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141669 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4799700ljj; Wed, 11 Jul 2018 00:41:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeRDHp2Ln6GAVUQ6tuPhXfEAIgciGtbd9eDQkm3flgx4nLtqDwEXtGf+PsPxq5vqhTKsnzT X-Received: by 2002:a62:d693:: with SMTP id a19-v6mr28707835pfl.248.1531294906254; Wed, 11 Jul 2018 00:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294906; cv=none; d=google.com; s=arc-20160816; b=uhTuJhm2cf4xMvURG9gFy9CMR5WUZgsO+9A3lAE3MCNVRhlbF4mVyo7j2zKjZHlh3F BBSBfYtM/LhctGewO1ioOmQfaRBWe639u4vAtW9f3G0qC2eIzYhyzef/dTkC9XePXK0F nF9FTJLsLdQzlAdPkNn7wDDvya0yKXKvS8OD8s9TGzhV2nrNehi47QVkQdXp9LBC8RnZ BwTDMQjlZN2px+R3//nNjKDDjYCnEd92XX7c9+U/F9yZOq0in27i4s/U2N2D730khi6S miIJEVCCQ5Uw287Lr62/UayU4y2q3qc11zOHEwCxmj62abH8hnVKc0VYXpoAAwq+mLNJ Z7PQ== 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=hcyD5bzBlMQbAFyjVm5uzlDDpIhRGR7j0yPAOy1/9Is=; b=R0WvoE+NXVGbmbYDW1Kdxv55yJDm4gPa//+F7IdsMyTe3uHG4NcWc09axAgnHIdY1c mWADeWUx32KmGAPikBwFb6HXOg4sOqnZqt1n4UfGaLl9q5sE3lDnWZxVn3ORASzz+/4r fIMNKGRdkw7oro5djxtBsZ+BdYhDxeErFMmbKR2wM7g24AYDkBMc9YdlRKu7Qgw+sG/P UKPhPipMfsNPD5sDXepHn6FnyEZibYteQZ9uZ4ykMQzlfyibtlcVOe9jlDmaJesP/xhv OA6yQ64RwLuI//mNt0843Rx95+lYkctBMm2txDJY2S/JmhJuFtrE7ivFn56rgHmAAAmv IrCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D0IWLzid; 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 77-v6si20121449pfh.332.2018.07.11.00.41.46; Wed, 11 Jul 2018 00:41: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=D0IWLzid; 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 S1726588AbeGKHoj (ORCPT + 22 others); Wed, 11 Jul 2018 03:44:39 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44411 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeGKHoj (ORCPT ); Wed, 11 Jul 2018 03:44:39 -0400 Received: by mail-pg1-f196.google.com with SMTP id r1-v6so2686765pgp.11 for ; Wed, 11 Jul 2018 00:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hcyD5bzBlMQbAFyjVm5uzlDDpIhRGR7j0yPAOy1/9Is=; b=D0IWLzidIP460MwlrQAG6aeF2+wQJfsdDVp4sxz2rV6CBYykEPx9kJafLWl8/24Izp aBJMYleQySH+AEvDxpml4JhRLirMDCdI0nyFbiR1OSvWAEfj7RRTITx5GkIFI1GZomOC mjB1OxQ7nC/1WvViv/ENHY915vprkVR7BhIno= 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=hcyD5bzBlMQbAFyjVm5uzlDDpIhRGR7j0yPAOy1/9Is=; b=XtFD+pQp5QM8onw8iGgqcuMhcPGJKxr0YOfs7i1YDMJ5ZboAm4XgcGHZhpVzxemKev XikVEpoct5CTZTGyciGrIeIoqnqV8Ij1kbHqm8zf4apSGRnjZIfrL/GY+Ydu3GHeDZ+8 g+EmTtAjDLMwDa3Rd+531oOUmDHRTfUFg4bO5R7uh6L2WsGHXcAnSo3gxw7wdt39zQR+ vJR9dXw1p8UhwPXstKouzmAGZrs6x7dLY29FI+UIc97qOrVdThTaBocnwO69TrKxwnOI ChdSoFOsID+g5hlQ9C9CmirEWNeHVCas/+ZCzVn/WWd6ppPOCRxjyBh53IGg0f60wUAz iUaw== X-Gm-Message-State: APt69E02uTmdb89OXDUEa9ujOsMq2mi6QnGEqGV6P+cYjXLvBwwkpg0S FW1Ih6dN6jhZft/ZXjhXwW5jew== X-Received: by 2002:a65:40cd:: with SMTP id u13-v6mr26126916pgp.334.1531294902996; Wed, 11 Jul 2018 00:41:42 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s144-v6sm4342192pfs.123.2018.07.11.00.41.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:41:42 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , "Eric W. Biederman" Subject: [PATCH v11 03/15] powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem() Date: Wed, 11 Jul 2018 16:41:51 +0900 Message-Id: <20180711074203.3019-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memblock list is another source for usable system memory layout. So powerpc's arch_kexec_walk_mem() is moved to kexec_file.c so that other memblock-based architectures, particularly arm64, can also utilise it. A moved function is now renamed to kexec_walk_memblock() and merged into the existing arch_kexec_walk_mem() for general use, either resource list or memblock list. A consequent function will not work for kdump with memblock list, but this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro Cc: "Eric W. Biederman" Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He Acked-by: James Morse --- arch/powerpc/kernel/machine_kexec_file_64.c | 54 --------------------- kernel/kexec_file.c | 54 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 54 deletions(-) -- 2.17.0 diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c index 0bd23dc789a4..5357b09902c5 100644 --- a/arch/powerpc/kernel/machine_kexec_file_64.c +++ b/arch/powerpc/kernel/machine_kexec_file_64.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, return kexec_image_probe_default(image, buf, buf_len); } -/** - * arch_kexec_walk_mem - call func(data) for each unreserved memory block - * @kbuf: Context info for the search. Also passed to @func. - * @func: Function to call for each memory block. - * - * This function is used by kexec_add_buffer and kexec_locate_mem_hole - * to find unreserved memory to load kexec segments into. - * - * Return: The memory walk will stop when func returns a non-zero value - * and that value will be returned. If all free regions are visited without - * func returning non-zero, then zero will be returned. - */ -int arch_kexec_walk_mem(struct kexec_buf *kbuf, - int (*func)(struct resource *, void *)) -{ - int ret = 0; - u64 i; - phys_addr_t mstart, mend; - struct resource res = { }; - - if (kbuf->top_down) { - for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, - &mstart, &mend, NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } else { - for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, - NULL) { - /* - * In memblock, end points to the first byte after the - * range while in kexec, end points to the last byte - * in the range. - */ - res.start = mstart; - res.end = mend - 1; - ret = func(&res, kbuf); - if (ret) - break; - } - } - - return ret; -} - /** * setup_purgatory - initialize the purgatory's global variables * @image: kexec image. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 63c7ce1c0c3e..b088324fb3ad 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -501,6 +502,55 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) return locate_mem_hole_bottom_up(start, end, kbuf); } +#if defined(CONFIG_HAVE_MEMBLOCK) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK) +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + int ret = 0; + u64 i; + phys_addr_t mstart, mend; + struct resource res = { }; + + if (kbuf->top_down) { + for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, + &mstart, &mend, NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } else { + for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, + NULL) { + /* + * In memblock, end points to the first byte after the + * range while in kexec, end points to the last byte + * in the range. + */ + res.start = mstart; + res.end = mend - 1; + ret = func(&res, kbuf); + if (ret) + break; + } + } + + return ret; +} +#else +static int kexec_walk_memblock(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + return 0; +} +#endif + /** * arch_kexec_walk_mem - call func(data) on free memory regions * @kbuf: Context info for the search. Also passed to @func. @@ -513,6 +563,10 @@ static int locate_mem_hole_callback(struct resource *res, void *arg) int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(struct resource *, void *)) { + if (IS_ENABLED(CONFIG_HAVE_MEMBLOCK) && + !IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)) + return kexec_walk_memblock(kbuf, func); + if (kbuf->image->type == KEXEC_TYPE_CRASH) return walk_iomem_res_desc(crashk_res.desc, IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, From patchwork Wed Jul 11 07:41:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141670 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4799829ljj; Wed, 11 Jul 2018 00:41:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeWuOzGbd41CBzPZQhreJSpD326zlze/uxcFAutt4cALkFl9zAVVAFy6piEqSU6ZQb0Xgof X-Received: by 2002:a17:902:1ab:: with SMTP id b40-v6mr10942732plb.55.1531294915013; Wed, 11 Jul 2018 00:41:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294915; cv=none; d=google.com; s=arc-20160816; b=IG4nPhO2pSIHiVithqN6NvqlAH03rAhQweqplwdfXQZQuHYdTnknKWTdz+39SiZ8g0 DkC605dw9d8wMDhcfNeXHkH59rTYf78TAGErQtzSSlvjL+xp2lvRxiDO/8TWYmxocsf+ 7bP7Dv5x7XYZY8gQUHlnZB3gqIlGg6Rd0qhiMBuVrloLq1jXCkKQKGuY+FbWujKKAaWy Dt8kFbgzm1DMzs3JHK1x9RfND7xL/PDkfC81nijBwSEhlJLGcmRyIvK5lBAsHimuo//7 GKAagzGCJf+yLtp4wTorMU97ywK9NC8sUSjJcR+WjHBQB2p2FRNyl83TYk2Kf83VNve9 d4RQ== 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=PItXgTakqtWpQdCyBHziU3bBiq2X1/Ekd+7Czkvk2eo=; b=alB/h/Nu3xGTG+D/jHM0BL8u2OjvSsC6bY6oT8TKfPbVupGup0N68A1cv0VQ0oFO7O nZJPkXlOQzZZqe3aHjx90v1xuqXdFr6XU38D41dMYgYqr8vP0Xdz9o0h+1rOKyr6Akw2 5kJyWAR0wb7vy8sIpzYYTR8swA5n/00XGoTxqiqGwtq96TlHsfssfG3+/ua9aoFW1R/W dmJTRJiA+RljYmZREFMKMEeYb7vuaBueuJ00PIA/TcubaG7vBX2OqL6jFvdAxuadsVMv /ZsP4nL4XqddFLrRhnjlT0SXAc9Pc+/YerkoibwSL8zjsCxcp+trKy7gK5Z+X0pD/jf2 PShA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J4yi+GBU; 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 bc12-v6si18197769plb.373.2018.07.11.00.41.54; Wed, 11 Jul 2018 00:41:54 -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=J4yi+GBU; 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 S1726713AbeGKHor (ORCPT + 22 others); Wed, 11 Jul 2018 03:44:47 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:33441 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeGKHor (ORCPT ); Wed, 11 Jul 2018 03:44:47 -0400 Received: by mail-pg1-f195.google.com with SMTP id r5-v6so2644712pgv.0 for ; Wed, 11 Jul 2018 00:41: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=PItXgTakqtWpQdCyBHziU3bBiq2X1/Ekd+7Czkvk2eo=; b=J4yi+GBUU3ZdD5V4QCTl0/VkFq/9LrXzrTTb2HIvOgzhrh/gTY46d4Uqtztfl1/Twb 8Ld6FN7tnjq+cMQvaZKFpTifxHsmR7SCzzSWO68TGLBVO+sSrRKZwsqxMr0B9u97hoQT iP7C1slL0HeldBkE4fSunJLeI+cYDK9ISaY7E= 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=PItXgTakqtWpQdCyBHziU3bBiq2X1/Ekd+7Czkvk2eo=; b=cD2YjVFU8+nXGlMq4DtxgEfI7XQWRmKTvbfBgX6jKs9wFeDPK5kX5bGFtabp4Vz/Cs 33+jfHDpa2c7jBxvVagQNlehdN09XZlmPHhyOmH4tpiNkruezkuK5PhKqiEJd4+tnbt+ 98BsHLl8J72VV51TyPn14aI0r8em24FPedl5wSjhFWLzTlmzcKGCwh6EyyqLkYZQUQ3/ TbVYrpYFYTOA1VsBUKRHnIlI2mhopE4W0ktGGQT5zhUUjXTrFExjboEZch/s2tDQJX4P cBLL51pFT15w3/FDwM1pN7TCQB990b/2HDPnPKG8+Hp3uCZQb0GSbGh7Qa4vP3a4zcI1 /IJw== X-Gm-Message-State: APt69E3Yf+X73F1UWPYUG8N7pHH87LipJ+fHF6gqb/SK0of4Pb0VnNw9 1ZQr1WuFZ8fpV9f/8HKTKtmh8w== X-Received: by 2002:a65:5bc4:: with SMTP id o4-v6mr19428518pgr.448.1531294911472; Wed, 11 Jul 2018 00:41:51 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s144-v6sm4342686pfs.123.2018.07.11.00.41.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:41:50 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 04/15] kexec_file: kexec_walk_memblock() only walks a dedicated region at kdump Date: Wed, 11 Jul 2018 16:41:52 +0900 Message-Id: <20180711074203.3019-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In kdump case, there exists only one dedicated memoblock region as usable memory (crashk_res). With this patch, kexec_walk_memblock() runs a given callback function on this region. Signed-off-by: AKASHI Takahiro Cc: Dave Young Cc: Vivek Goyal Cc: Baoquan He --- kernel/kexec_file.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.0 diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index b088324fb3ad..ebf06c3e168d 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -511,6 +511,9 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, phys_addr_t mstart, mend; struct resource res = { }; + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + if (kbuf->top_down) { for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, &mstart, &mend, NULL) { From patchwork Wed Jul 11 07:41:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141671 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4799977ljj; Wed, 11 Jul 2018 00:42:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcLqXI9/X8h8TZJ0X35bg4HrDFqN97zFW6q+w5Ga+afGe8eRvsMnpOxaImIzty/Be32Nhsh X-Received: by 2002:a62:c0c4:: with SMTP id g65-v6mr28707597pfk.72.1531294924769; Wed, 11 Jul 2018 00:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294924; cv=none; d=google.com; s=arc-20160816; b=L0RDJnDeVsOBNsAUh/yNPeXcrQGJoif9Z1rMAHbY8eR6ctQlJMU5qbwOmYvWDhNTZ8 /lqRaRwszbDVo68vu/D+QVmrwgZoVWj52w+jA61ax0uYj93mvWx3SSdq7dw9G/vViwuH U2R/NKOyE6/PskNcsZMCQw4v+mzo3tzUrrExoEwlG2sRsPb7PY+1tY7XC+4pPDGhY6Eg T8eiIJYTi49o9X6qztkAH6WFi/kOLjR6akjB3eR/XsDMEDdg+9JH2pHDcS4ZsS4krZOn LLsOfe8IaaboY8PGi26f2TBMZAj5/TG/e77H0y2WoQMAXbydmJVeZefdMa9sqZD5GgF2 XQ3Q== 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=QlhV7eDSbsU4GPDGTwzyQDGWNJMnX8a7YNDVlGTagBM=; b=ccQ0a0WFPQMrD/bs/H0pwNo1cxf7zg+lTvsBlDuQI4baEso/fq0hpLiGGUuiHjBzf3 Y4evm33D9LziyBsmIS7FsZsZOlKyrtNgeND6NBgsybKKNm9vtx2BpR13fC3B4rgYwrG2 2RH/hYTpLQv8wy3TMcYpPqdxZy3aSO+pG3EjfdjIWn/jtRyfA+G82AVcD6B5GlAlq2oI Mqe4jUInEdRhRPPSnKZGNc6AylzpK/y+lOjdemc4obbTPXfp05O/AMO9ODFMU1e1yARd bnVAyFfIBrnbz2Jv+/ZqQ672AEq2eu9MY0oJwxWq5ZiLW2jBatapxEgqw1rPH3iZ1Ngm NhXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DXQZ5Wpy; 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 l26-v6si17887254pgu.191.2018.07.11.00.42.04; Wed, 11 Jul 2018 00:42:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DXQZ5Wpy; 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 S1726784AbeGKHo5 (ORCPT + 22 others); Wed, 11 Jul 2018 03:44:57 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:42724 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeGKHo5 (ORCPT ); Wed, 11 Jul 2018 03:44:57 -0400 Received: by mail-pf0-f171.google.com with SMTP id l9-v6so6236545pff.9 for ; Wed, 11 Jul 2018 00:42: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=QlhV7eDSbsU4GPDGTwzyQDGWNJMnX8a7YNDVlGTagBM=; b=DXQZ5WpyyE/KxO3vIz5rWYCBHP7Lq8wvgXXdAfcutCKQ1PjOwNUMf9pHWjihE7kCN6 wCRwpC0/G/+BB97oJk3u5bGddZchoyATlbRWnK7k31Ymk75J2/XTNuV8C0Y80zVDHCxL t5Xdfigyj0cD+P2602F/sN+miEljoBN2AMtak= 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=QlhV7eDSbsU4GPDGTwzyQDGWNJMnX8a7YNDVlGTagBM=; b=MJzDPjJYirlxdKDVTB95utIJOcPXkh7MZxfDkZbEkYe5FCzTeEbqzO24nM6h3ehjU1 upay//NpQGyOeZlhyAvES4RhZSPzGDPTdFScqSIzpnFK5Vr0vw609UoZZ/p09EMtXzRX Ej2OcD3U8GdFQ45giyJIu6QCsS0cAvUz7SNSn3x/khtchpFNM12ADmFKfNEDzFlc9+SN 8gExsJ0tqf4MUhxRM+J+6QI4TDq/h8V2HW+QCUXrQUC+u0wwDUp11bIR/pKQvZ51cYJD qye6YzFkJA9kcvpaDRrK4CfyTEQg2gfuO4TEtBHRoqaK8L38XuO1bxG9Yaee8g0EuUwZ XSOQ== X-Gm-Message-State: APt69E33V6JMsFlvat0S2uJZuYxKyoEnhYlKgfQe6W1qZwHymjZgTRIX XihJgVrOUfOasUbeuguz1EEMkg== X-Received: by 2002:a65:6689:: with SMTP id b9-v6mr25416801pgw.326.1531294920730; Wed, 11 Jul 2018 00:42:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p20-v6sm29051873pff.90.2018.07.11.00.41.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:00 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , Rob Herring , Frank Rowand Subject: [PATCH v11 05/15] of/fdt: add helper functions for handling properties Date: Wed, 11 Jul 2018 16:41:53 +0900 Message-Id: <20180711074203.3019-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These functions will be used later to handle kexec-specific properties in arm64's kexec_file implementation. Signed-off-by: AKASHI Takahiro Cc: Rob Herring Cc: Frank Rowand --- drivers/of/fdt.c | 62 ++++++++++++++++++++++++++++++++++++++++-- include/linux/of_fdt.h | 10 +++++-- 2 files changed, 68 insertions(+), 4 deletions(-) -- 2.17.0 diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 6da20b9688f7..f7c9d69ce86c 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -25,6 +25,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -537,8 +538,8 @@ void *of_fdt_unflatten_tree(const unsigned long *blob, EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); /* Everything below here references initial_boot_params directly. */ -int __initdata dt_root_addr_cells; -int __initdata dt_root_size_cells; +int dt_root_addr_cells; +int dt_root_size_cells; void *initial_boot_params; @@ -1330,3 +1331,60 @@ late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ + +bool of_fdt_cells_size_fitted(u64 base, u64 size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((dt_root_addr_cells == 1) && (base > U32_MAX)) + return false; + + if ((dt_root_size_cells == 1) && (size > U32_MAX)) + return false; + + return true; +} + +size_t of_fdt_reg_cells_size(void) +{ + return (dt_root_addr_cells + dt_root_size_cells) * sizeof(u32); +} + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + __be32 val32; + + while (cells) { + val32 = cpu_to_fdt32((val64 >> (32 * (--cells))) & U32_MAX); + memcpy(buf, &val32, sizeof(val32)); + buf += sizeof(val32); + } +} + +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size) +{ + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + buf_size = of_fdt_reg_cells_size(); + prop = buf; + + fill_property(prop, addr, dt_root_addr_cells); + prop += dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, dt_root_size_cells); + + return fdt_setprop(fdt, nodeoffset, name, buf, buf_size); +} diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index b9cd9ebdf9b9..9615d6142578 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -37,8 +37,8 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node **mynodes); /* TBD: Temporary export of fdt globals - remove when code fully merged */ -extern int __initdata dt_root_addr_cells; -extern int __initdata dt_root_size_cells; +extern int dt_root_addr_cells; +extern int dt_root_size_cells; extern void *initial_boot_params; extern char __dtb_start[]; @@ -108,5 +108,11 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +bool of_fdt_cells_size_fitted(u64 base, u64 size); +size_t of_fdt_reg_cells_size(void); +int fdt_prop_len(const char *prop_name, int len); +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size); + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_OF_FDT_H */ From patchwork Wed Jul 11 07:41:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141672 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4800087ljj; Wed, 11 Jul 2018 00:42:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdSV/pm6OrfInsA2km5T+sfj5ynY6cf/iAPQZ5hQv82GbNNirllZOKfa0cz/GhmcMuqIAoE X-Received: by 2002:a63:4763:: with SMTP id w35-v6mr25328620pgk.140.1531294933726; Wed, 11 Jul 2018 00:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294933; cv=none; d=google.com; s=arc-20160816; b=yJ0IfkP9DLOOhhAbJXEw7+Ef/kN0IMeWE1v5RURmFmx6pQUzoeAsk+TdjJOzHYfE+a ffvlhZWNFI88OCfPTs1h7MsjfRdV40hIirIPMbf3SL4xthSMtqH+41yqai/N7DkTpYPa In8CPvobAXT8KGXbWzYE4Ac84auBgzwfupNRZwiDuDrNjITiC3SawCgHTV18xgNKl/zv JCinlxJXZdTEdRLxBVgBUDgEjq2ZwnbTr/pZ3sqI7+tlm9ARGBFZWRZeRAcTTGVVIPCr TnOavg4yUhgeYTClqlJzgMmY5j2Ex7+IQCqEuMjPZM7oVboEylPYxsya59VP2+m+xhsu A/7g== 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=uP6g9dIg20P4WZ2r+N/9W+9rosj1Tr0GUJ5X7xgjy0E=; b=Np8INsDLIoK5PQ/EC9PQU5aPjEoTs66RWR0cBixb9mNhHWNcocGN4RnPVSS2fX9jo1 hD9u91RrHw38DEU94Cud/WqtbBHU1Gfp5djI472rvXFYYIYd3LytIi0HfcYotL7vgSdn b4NPgtqobSgf7YD2OEp3DjHS8n8h4XGsoLDn/qEtKeCqca17Rg2UWQhrx7sg2tlTI5On Pcwd4Y4fybuduFJCZIlZZbKogt0liQSpLsMKpw1lcBH4w09lGWCKawlgqEk5hT/FQC0p ZihKPku47fMtRNvyQYi36Zggpf2nMN8VzbNEiL6k+tmHhWIWhuh4CKj6v1Vx4cocg3nO Dd0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="CajYu/jR"; 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 91-v6si18434505ply.296.2018.07.11.00.42.13; Wed, 11 Jul 2018 00:42: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="CajYu/jR"; 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 S1726832AbeGKHpH (ORCPT + 22 others); Wed, 11 Jul 2018 03:45:07 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:40878 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726787AbeGKHpG (ORCPT ); Wed, 11 Jul 2018 03:45:06 -0400 Received: by mail-pl0-f66.google.com with SMTP id t6-v6so8805020plo.7 for ; Wed, 11 Jul 2018 00:42:10 -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=uP6g9dIg20P4WZ2r+N/9W+9rosj1Tr0GUJ5X7xgjy0E=; b=CajYu/jRuy62ocVoOcQvS6x6/xHOywT1GWvp13rh/8v+XGaXmUOU5lx02fGRI3BL6o aeu6X6vJBKHVAnQuZaHTLmMoc0CP4glXhbcpNZM//kb6bk+2dQOaF+n/nKanWuNV8pTC wm1gwYT8vTQ6JGYvSa9Qyd8zMS79hUz5l6Bq0= 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=uP6g9dIg20P4WZ2r+N/9W+9rosj1Tr0GUJ5X7xgjy0E=; b=mQrVTGZSFxKVKHGcVR8+CZS/ISz6tcTZ/hHVburT/2w5WBXTTscDMJgwp9EVztV6+Q /MlpY+gmNt8S1ZxMJ48ZGJSiSHO5WzmWt0gyPHVrpoI2ilMJcmnEkXIxzSGqwru+bQ57 tDUdlRPHOKQuz1F4sL1mjY9bW/6AOM1yA6GEArbh4otl2JR6+Y1aVxxoOd3pEiq6OGGi HYk7/hM3Zu8yku8d6YMvgJ/X68Fsqbe/l5BUn/Mr94/MPoNG4etXKKu9RFI006UcZzeK gH3hUGi9SmiGOADeAVljBWzXEtSv93dfQ++oKaGkjSU7wq6+4dkPhwb1gPD0eJJiNFF9 XuqA== X-Gm-Message-State: AOUpUlEn0muQ81RgeTLRvoSxmT1ATIhbs0OfVO6P/PFdghlosgC0wuZc T3LcoQarsK9lcfyIM/yZ2Jy5SA== X-Received: by 2002:a17:902:4a0c:: with SMTP id w12-v6mr485209pld.289.1531294930498; Wed, 11 Jul 2018 00:42:10 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g124-v6sm30862281pfb.5.2018.07.11.00.42.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:09 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 06/15] arm64: add image head flag definitions Date: Wed, 11 Jul 2018 16:41:54 +0900 Message-Id: <20180711074203.3019-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Those image head's flags will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Acked-by: James Morse --- arch/arm64/include/asm/boot.h | 15 +++++++++++++++ arch/arm64/kernel/head.S | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) -- 2.17.0 diff --git a/arch/arm64/include/asm/boot.h b/arch/arm64/include/asm/boot.h index 355e552a9175..0bab7eed3012 100644 --- a/arch/arm64/include/asm/boot.h +++ b/arch/arm64/include/asm/boot.h @@ -5,6 +5,21 @@ #include +#define ARM64_MAGIC "ARM\x64" + +#define HEAD_FLAG_BE_SHIFT 0 +#define HEAD_FLAG_PAGE_SIZE_SHIFT 1 +#define HEAD_FLAG_BE_MASK 0x1 +#define HEAD_FLAG_PAGE_SIZE_MASK 0x3 + +#define HEAD_FLAG_BE 1 +#define HEAD_FLAG_PAGE_SIZE_4K 1 +#define HEAD_FLAG_PAGE_SIZE_16K 2 +#define HEAD_FLAG_PAGE_SIZE_64K 3 + +#define head_flag_field(flags, field) \ + (((flags) >> field##_SHIFT) & field##_MASK) + /* * arm64 requires the DTB to be 8 byte aligned and * not exceed 2MB in size. diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index b0853069702f..8cbac6232ed1 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -91,7 +91,7 @@ _head: .quad 0 // reserved .quad 0 // reserved .quad 0 // reserved - .ascii "ARM\x64" // Magic number + .ascii ARM64_MAGIC // Magic number #ifdef CONFIG_EFI .long pe_header - _head // Offset to the PE header. From patchwork Wed Jul 11 07:41:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141673 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4800251ljj; Wed, 11 Jul 2018 00:42:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdLBQ1iJqVG9qMJcIrHTMus8/PIAwg/miYmGZGC8/4CNMnaHix2v8HmhQtAjmb7Jxigu3SM X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr27232484pln.197.1531294944473; Wed, 11 Jul 2018 00:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294944; cv=none; d=google.com; s=arc-20160816; b=YLrxTqfsh2FPMry+7bEzX2Vyv4c6gEDK2teVmZZvbKXFGAoL4WSytS4+m3Sq1FaznS aQIZhuVcZpX67alYFTlcC+bBi7lrlG5JApCnocDzbh8u3vdJ12kph/qnIhwLVyKza9zR 3/Rtzhk2x5INw3Xmxc/9Gl9+aBC57oFM8R5cYdiaVBZFsUQo9MY1ypWCtqAO6pzlB/+s qTJFMysP6yr7KDDwyzyHYG6MsAQUt3gcHlkQcqBlDrUiLFMx+jiIuD+417cgNmUFwITo OneQhsMeSXP3CuQcfKTjvoWAmf2jaEdPhye3l14hFIuVM9kjJt+R0A4J2/iZt0oZ+7ce ErvQ== 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=uswfCd93e0qJR+3NeyRPsd43EHwi1pdW3kTaED3pE8E=; b=CbsIXgqLvuzgC5sQ8b4gI1zIal22GUHnci33SzXaKwtzJFtsfzo9U1RkU2PPdru7Jl 8YgEw8pLiGHyAk6QjQsSuXQxCcYqYmQ5ul1bJJuAbi15RoktaiF1EqC5CRFvXdjGar7r 1MQmAyFHej1pSh+O+VWIc6/CmVOm1j72f/KK3bAvdJw6lrJnVHSvYeEm/e+WVUOJUzLR PZsDCWoN8DNUBUrc2kDsJGkCPD6YsxzxOkVydhPp9m8H0KalOmrMbKkikguyEsdry04z FJ/vq9PgSmqOrmf2om59ZFH2LzoM2XUu9MUBMHowX2G1zziF4jWzd5MDCuBnF3M7og8F M1nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z230q3lp; 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 y2-v6si18325308plp.459.2018.07.11.00.42.24; Wed, 11 Jul 2018 00:42: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=Z230q3lp; 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 S1727215AbeGKHpR (ORCPT + 22 others); Wed, 11 Jul 2018 03:45:17 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:40889 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726410AbeGKHpR (ORCPT ); Wed, 11 Jul 2018 03:45:17 -0400 Received: by mail-pl0-f66.google.com with SMTP id t6-v6so8805230plo.7 for ; Wed, 11 Jul 2018 00:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uswfCd93e0qJR+3NeyRPsd43EHwi1pdW3kTaED3pE8E=; b=Z230q3lpLDRUO6KPcurb/pBZplwXRi3kDbCO5IKatDsR5+61CIDNH/2fUz7wt8TVkS DXiuYnbeD49VFg/sRwO6VMmmPZMPxYNLDgMecIoUkF2KcYi8Xh7Mp1RdCBLFOhxr6ti9 bkzYt9naojosaLZ+tUhDg3OLCJWgRdMRVVsNg= 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=uswfCd93e0qJR+3NeyRPsd43EHwi1pdW3kTaED3pE8E=; b=C1xMK837Kr8iCad3OeiSjF/GyBCQ8i4NmUVsSqHVgjoBGog9a1NDwSf25SSeF/pI3k mIh+wXq3KvC35onZYAJz6REfzRuQSxgQ69OAXESetsPRgqGxwaSq1E6t7Um2wxwFI4bm 1oCVfvUwOfkMtA4pvNIEJwP/XsyftelwG5OMoIOpH7OS8e81Uj3Y7v7deR9If2oJtLiT 5SxpGhQyBTUodQRJA9mKIikszRGLGkTCp5kO3r1jWFZZtk5m+81bM5ddqZF/dQM32Cv0 BBKj7yFUuQhXYc+uKfBTNWeMiVuwFACuHt9dK50hwX15DJpQDCrmR23BhldBUuUcnt5J 5C/g== X-Gm-Message-State: APt69E1CvlefoIxXEAwx5ZL5n1mmHWieM7jytO46yWZop0TRiHsUkgf9 zOgzHSUd+1yJKwg2XKz9N+kmcQ== X-Received: by 2002:a17:902:a60b:: with SMTP id u11-v6mr27620867plq.158.1531294941053; Wed, 11 Jul 2018 00:42:21 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id q28-v6sm36911949pfg.144.2018.07.11.00.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:20 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 07/15] arm64: cpufeature: add MMFR0 helper functions Date: Wed, 11 Jul 2018 16:41:55 +0900 Message-Id: <20180711074203.3019-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Those helper functions for MMFR0 register will be used later by kexec_file loader. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/include/asm/cpufeature.h | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) -- 2.17.0 diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 1717ba1db35d..cd90b5252d6d 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -486,11 +486,59 @@ static inline bool system_supports_32bit_el0(void) return cpus_have_const_cap(ARM64_HAS_32BIT_EL0); } +static inline bool system_supports_4kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN4_SHIFT); + + return val == ID_AA64MMFR0_TGRAN4_SUPPORTED; +} + +static inline bool system_supports_64kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN64_SHIFT); + + return val == ID_AA64MMFR0_TGRAN64_SUPPORTED; +} + +static inline bool system_supports_16kb_granule(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_TGRAN16_SHIFT); + + return val == ID_AA64MMFR0_TGRAN16_SUPPORTED; +} + static inline bool system_supports_mixed_endian_el0(void) { return id_aa64mmfr0_mixed_endian_el0(read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1)); } +static inline bool system_supports_mixed_endian(void) +{ + u64 mmfr0; + u32 val; + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + val = cpuid_feature_extract_unsigned_field(mmfr0, + ID_AA64MMFR0_BIGENDEL_SHIFT); + + return val == 0x1; +} + static inline bool system_supports_fpsimd(void) { return !cpus_have_const_cap(ARM64_HAS_NO_FPSIMD); From patchwork Wed Jul 11 07:41:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141674 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4800393ljj; Wed, 11 Jul 2018 00:42:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdhearHNokJYtAEC0k0jkr97hN44MAR/NUMW+o0deCbAcsxiqykHOaId2C/S2xR8W8K/X28 X-Received: by 2002:a63:2e81:: with SMTP id u123-v6mr25411448pgu.225.1531294954049; Wed, 11 Jul 2018 00:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294954; cv=none; d=google.com; s=arc-20160816; b=DN+1p4D5d19CFAk5bKEtZyLt2MX1sSYszs4sY9jXvHpUSGWG5BbV0B55qJbNzZ0KbH viABkhf5TTPflUUAXLZwfg0Rn5ItgofFk/0cmLJ9BpgQ3gHWWcUeenP0TjSTYcgdCt1W aiFTavmLTGGCaGxUGP/AjhWl/28rfR0hWgiMObOYKfWQDxXF0mP9CUcB9PTqwuUj1aVm VGlab7+JI5MRcP72LY+Ci+YyBBBa9O7gI3xBbTMlpzRCdsSvQJl19jQ9fySVyVn1XMBa p/BC+gYCwoLLrVFQN9gJVHnCp6tVYyN1PAYAxhzmHpZB1fqpasqve3crZC1F1l7utCqb Ngjg== 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=m0uS1Rp3rP12XbuAKF03IvNckGWO0+g7J4IbvlkBpFw=; b=OOninNmoj2jkev0PJVVgEXal95HyYNNR2ndt/d1T09kJ/poOJm9XOSvjvbpS4dGIma itY5JFdx/xzMIoImslExQwQ6JIUf2s/AyEv4JakLmvTzF666o33G+S3zlKAPe44KHRZG DNsHGvsraqXoe8YgAOhmJLLlDWscv+s5IFnYAP+FN6aEasc/gGPs4zhDRJN4GWuo/NJe 7jYs6OLJpN/qR6Y5QHpAC+jmTiF1XKe/NH7yrvyB6NJXu06OoPow1QOmYnhzZI7FMwFL tCoKpaQt3wmWN3Q9g1NnIov+u6+cTurjRrRl3x88Pq0HcQLn3vJOfaxIpANRRJolfVvW n41Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DAtkP1oK; 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 x24-v6si18481546pln.22.2018.07.11.00.42.33; Wed, 11 Jul 2018 00:42:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DAtkP1oK; 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 S1732297AbeGKHp1 (ORCPT + 22 others); Wed, 11 Jul 2018 03:45:27 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:39218 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726306AbeGKHp0 (ORCPT ); Wed, 11 Jul 2018 03:45:26 -0400 Received: by mail-pl0-f67.google.com with SMTP id s24-v6so8804002plq.6 for ; Wed, 11 Jul 2018 00:42: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=m0uS1Rp3rP12XbuAKF03IvNckGWO0+g7J4IbvlkBpFw=; b=DAtkP1oKxpQjbcHAbqs5+uhJHnYUcHpsgvA+27+mYwaNTRzCrIP3RBnKmgW28nyiFw 6Z+WDvy/lycFtAtdGfYARQhsgqyhw5tI6AXEuqlOP2Hpl4obXGNhFV0FwK4H4HMOSBHU oyC3XohhZN3/aTZyPy/u5B8LbY808r5t+QEjw= 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=m0uS1Rp3rP12XbuAKF03IvNckGWO0+g7J4IbvlkBpFw=; b=MO31GpAkelPY8gaxXeVG83NwjTNVjB4TsbkJIIRLZTWCczRNxGNa5HnlJSEwnA2LD/ 8uf55rfCB7UtoynEHmlZ2buz7i7nfQQtfMT8oaK0mHJgTeIplvnkhmFAkhZT5jSxto0D jJq7txDobLuVMab7dsjQMRjt+pxN84BXkFn19kxiPsx3yDzg72YWlO8rV6jxaHOV+nZr 68w5OMtGmnJnsMHqDDF0D8PP/T9asYSUVUOUfZqJeTgIzHy0uWYxVijBtQbZeIhFH5/2 UzfYaCQjkZh1ESgWYGAuiVWsjMdMTmXkEpE2l+fRnFGjkjma+Quk4vHGs/LRFTccNbYm 7Gaw== X-Gm-Message-State: APt69E0xT2v5alyjJrq6PvCKHL2pGvCVk2LMD2lBQCT0KRVeLOlhm2if mQbnBN4GhyiYG60Kxc0TvGRM3g== X-Received: by 2002:a17:902:b693:: with SMTP id c19-v6mr12412743pls.114.1531294950292; Wed, 11 Jul 2018 00:42:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h2-v6sm24520504pgc.90.2018.07.11.00.42.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:29 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 08/15] arm64: enable KEXEC_FILE config Date: Wed, 11 Jul 2018 16:41:56 +0900 Message-Id: <20180711074203.3019-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Modify arm64/Kconfig to enable kexec_file_load support. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Acked-by: James Morse --- arch/arm64/Kconfig | 9 +++++++++ arch/arm64/kernel/Makefile | 3 ++- arch/arm64/kernel/machine_kexec_file.c | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/machine_kexec_file.c -- 2.17.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 42c090cf0292..a9a3a5583c8b 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -835,6 +835,15 @@ config KEXEC but it is independent of the system firmware. And like a reboot you can start any kernel with it, not just Linux. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + help + This is new version of kexec system call. This system call is + file based and takes file descriptors as system call argument + for kernel and initramfs as opposed to list of segments as + accepted by previous system call. + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 0025f8691046..06281e1ad7ed 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -48,8 +48,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..c38a8048ed00 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include + +const struct kexec_file_ops * const kexec_file_loaders[] = { + NULL +}; From patchwork Wed Jul 11 07:41:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141675 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4800507ljj; Wed, 11 Jul 2018 00:42:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfHorGCBzD2YfSiGU60paUcxXBxM3YR6YFCyJQiDD0i3wHFeWSDYLmilpai0azW+EQ/GlXd X-Received: by 2002:a17:902:2c83:: with SMTP id n3-v6mr27504235plb.211.1531294963914; Wed, 11 Jul 2018 00:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294963; cv=none; d=google.com; s=arc-20160816; b=ZhhyzXp4hNSNUghdRqYukRn3Zd2B9sAD/4lbUBWIJqX9t3kOtgd5NnpncJOhI9SbBo F11r/SySDtRdZQMMkxgtGI3q8P/WcHV4ZzXgRRyLN2waC80gtcjiusbST7LV60DNeFgl Iws2IQVm7Zk4TF5hqQ2PmPCt/Jv9zvDjA/gXubQ7i1Vylk6gJeVo+eFyPRh0n49mVyZA PcC5i2fJO35Kb1wCUhSd9xxwgPAqAUbYXJX3e4UKvoy7LR4ano4qr/KYQwXDZD1raw0n rjgH5CCQusJKH0nG9rbTkT7yvd+cqnX1kAIvII8T0kBGjEm80JIr+wmMw9fSNO8HdN8m 7JKw== 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=0PS6qjK3C7l7A2CIqkRFL2OjgXECavo5rLxY/13kKyg=; b=hOShrQ0UFRmwoeP8gRi9a10WwmGficyC8cq3lslI8MC0mETnlYSfG9KHUAAVf801DI zGzmxg6FK5kEizIEnr0A69+hiKS767rv+MGA2UV3DQBQkK+oskd0SdLhQWS/+o5+4svf 6QVFrqlVn2oKGgNnrxeOQFGlmEU7JbJ//+uRlKehL9uXHQPDdpebQflj0dd8gQJhPpvm Kk7AoqqcVXiFviX0AKY1yYRGAHl/yBJG7wXmcsjfrs7AZ1tmkfJ0AcUL+G9tCZPDAmpY YeLN9QlXV+OTaVKpLKvvjr3p2uzUeZ5pK5te2WKC1vkSBOCqmyKHD0mQFd1SEO0A4ymW sRFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fte2i7vO; 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 n7-v6si2062626pfn.241.2018.07.11.00.42.43; Wed, 11 Jul 2018 00:42:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fte2i7vO; 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 S1732310AbeGKHph (ORCPT + 22 others); Wed, 11 Jul 2018 03:45:37 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:46023 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726306AbeGKHph (ORCPT ); Wed, 11 Jul 2018 03:45:37 -0400 Received: by mail-pl0-f68.google.com with SMTP id a17-v6so2961100plm.12 for ; Wed, 11 Jul 2018 00:42: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=0PS6qjK3C7l7A2CIqkRFL2OjgXECavo5rLxY/13kKyg=; b=fte2i7vOo6y1qvB6gCpIOQEoM7stKeKyD896Gvfk0mpJPEe3JAvwdcIoODDdej7kuq shvasghY8A+/bec787iQKR/si1GwXNM2w8YuK/DRd60mLgGuMQhHoOQDidYxKZeRJm8a 7olb/Fnbn47MVuk5O5qLGyhy0V0Ez6CadBO6s= 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=0PS6qjK3C7l7A2CIqkRFL2OjgXECavo5rLxY/13kKyg=; b=DHKOucAV5obm0Rf5/e+e8kP4Z7xowINCcJYd28+UM4+fwTYGHyYXPzHc1mM6rky747 lpA+zOoXilr4J28fKA4zStJ+ez1utlgGoj+OJKbvycZJWZZ8IL367diP1kAgp6Iteov3 Xzz9NXG3SG5sxl9H1vSHIw0ClQ3T4pEN6O8m2KpUfVTconZejY7lg4cVbm2eDxdM5ftv lHuRJh1aNINcsV4Q+eujUEiEafnbiNQESXGqMIcwXx6nv489A6OrL+U336H489gfP9Qu Oe9sJWHKpWK+JwabbuMCGf/TTvMfM8ThAojb5uCALOlzfjkaYFZMdj6L/vmVBKxRrbaW ofzA== X-Gm-Message-State: APt69E0keuRX/YlL+prmwg0UrdS3EpY+fNJPwQgqNEeZJ999Nf2vOMP2 ekjvVAl9dv/oZjIzq1Vuv8sArg== X-Received: by 2002:a17:902:d24:: with SMTP id 33-v6mr28182750plu.22.1531294960284; Wed, 11 Jul 2018 00:42:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 10-v6sm44333804pfs.111.2018.07.11.00.42.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:39 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 09/15] arm64: kexec_file: load initrd and device-tree Date: Wed, 11 Jul 2018 16:41:57 +0900 Message-Id: <20180711074203.3019-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org load_other_segments() is expected to allocate and place all the necessary memory segments other than kernel, including initrd and device-tree blob (and elf core header for crash). While most of the code was borrowed from kexec-tools' counterpart, users may not be allowed to specify dtb explicitly, instead, the dtb presented by the original boot loader is reused. arch_kimage_kernel_post_load_cleanup() is responsible for freeing arm64- specific data allocated in load_other_segments(). Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/kexec.h | 16 +++ arch/arm64/kernel/machine_kexec_file.c | 184 +++++++++++++++++++++++++ 2 files changed, 200 insertions(+) -- 2.17.0 Reviewed-by: James Morse diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index e17f0529a882..01bbf6cebf12 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -93,6 +93,22 @@ 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 { + phys_addr_t dtb_mem; + void *dtb_buf; +}; + +struct kimage; + +extern int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len); +#endif + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index c38a8048ed00..ca00681c25c6 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -5,12 +5,196 @@ * Copyright (C) 2018 Linaro Limited * Author: AKASHI Takahiro * + * Most code is derived from arm64 port of kexec-tools */ #define pr_fmt(fmt) "kexec_file: " fmt +#include +#include #include +#include +#include +#include +#include +#include const struct kexec_file_ops * const kexec_file_loaders[] = { NULL }; + +int arch_kimage_file_post_load_cleanup(struct kimage *image) +{ + vfree(image->arch.dtb_buf); + image->arch.dtb_buf = NULL; + + return kexec_image_post_load_cleanup_default(image); +} + +static int setup_dtb(struct kimage *image, + unsigned long initrd_load_addr, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len, + char **dtb_buf, size_t *dtb_buf_len) +{ + char *buf = NULL; + size_t buf_size; + int nodeoffset; + u64 value; + int ret; + + /* duplicate dt blob */ + buf_size = fdt_totalsize(initial_boot_params); + + if (initrd_load_addr) { + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len("linux,initrd-start", sizeof(u64)); + buf_size += fdt_prop_len("linux,initrd-end", sizeof(u64)); + } + + if (cmdline) + /* can be redundant, but trimmed at the end */ + buf_size += fdt_prop_len("bootargs", cmdline_len + 1); + + buf = vmalloc(buf_size); + if (!buf) { + ret = -ENOMEM; + goto out_err; + } + + ret = fdt_open_into(initial_boot_params, buf, buf_size); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + nodeoffset = fdt_path_offset(buf, "/chosen"); + if (nodeoffset < 0) { + ret = -EINVAL; + goto out_err; + } + + /* add bootargs */ + if (cmdline) { + ret = fdt_setprop_string(buf, nodeoffset, "bootargs", cmdline); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, "bootargs"); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* add initrd-* */ + if (initrd_load_addr) { + value = cpu_to_fdt64(initrd_load_addr); + ret = fdt_setprop_u64(buf, nodeoffset, "linux,initrd-start", + value); + if (ret) { + ret = -EINVAL; + goto out_err; + } + + value = cpu_to_fdt64(initrd_load_addr + initrd_len); + ret = fdt_setprop_u64(buf, nodeoffset, "linux,initrd-end", + value); + if (ret) { + ret = -EINVAL; + goto out_err; + } + } else { + ret = fdt_delprop(buf, nodeoffset, "linux,initrd-start"); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + + ret = fdt_delprop(buf, nodeoffset, "linux,initrd-end"); + if (ret && (ret != -FDT_ERR_NOTFOUND)) { + ret = -EINVAL; + goto out_err; + } + } + + /* trim a buffer */ + fdt_pack(buf); + *dtb_buf = buf; + *dtb_buf_len = fdt_totalsize(buf); + + return 0; + +out_err: + vfree(buf); + return ret; +} + +int load_other_segments(struct kimage *image, + unsigned long kernel_load_addr, + unsigned long kernel_size, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct kexec_buf kbuf; + unsigned long initrd_load_addr = 0; + char *dtb = NULL; + unsigned long dtb_len = 0; + int ret = 0; + + kbuf.image = image; + /* not allocate anything below the kernel */ + kbuf.buf_min = kernel_load_addr + kernel_size; + + /* load initrd */ + if (initrd) { + kbuf.buffer = initrd; + kbuf.bufsz = initrd_len; + kbuf.memsz = initrd_len; + kbuf.buf_align = 0; + /* within 1GB-aligned window of up to 32GB in size */ + kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + + (unsigned long)SZ_1G * 32; + kbuf.top_down = false; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + initrd_load_addr = kbuf.mem; + + pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + initrd_load_addr, initrd_len, initrd_len); + } + + /* load dtb blob */ + ret = setup_dtb(image, initrd_load_addr, initrd_len, + cmdline, cmdline_len, &dtb, &dtb_len); + if (ret) { + pr_err("Preparing for new dtb failed\n"); + goto out_err; + } + + kbuf.buffer = dtb; + kbuf.bufsz = dtb_len; + kbuf.memsz = dtb_len; + /* not across 2MB boundary */ + kbuf.buf_align = SZ_2M; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) + goto out_err; + image->arch.dtb_mem = kbuf.mem; + image->arch.dtb_buf = dtb; + + pr_debug("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kbuf.mem, dtb_len, dtb_len); + + return 0; + +out_err: + vfree(dtb); + return ret; +} From patchwork Wed Jul 11 07:41:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141676 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4800646ljj; Wed, 11 Jul 2018 00:42:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdDJaLojM3TkTpwU5vjCA5bK0b5S/i//eF7VltjRT92imB6jgPHhMTs+PihpRHrXFpsmyVS X-Received: by 2002:a62:f704:: with SMTP id h4-v6mr29183162pfi.169.1531294976419; Wed, 11 Jul 2018 00:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294976; cv=none; d=google.com; s=arc-20160816; b=Puu7IsflpTiZslguNcymaC6CO7lGnJ2b50vhHrXRDA5V3dtnsWUgapeLEKlAFQdACF DI7NCIfwiLD9gcAB2NXpP+xTS2wlYMBOzWsGWgfodJlNUPZsAZV7eKvG8vxjvHerWwso AsYylFDL4brFh5DtaGHJK2tN+GJ3SykUwl5QHQK6gwlkEt0q6CHfLRPqpcjnhRt3YspZ NPaAwETdJRPo6nXjwlOMkitnMX5UVHMyQocenBduMY9u3vvkZC2qoZiGm1eeLmDEZRZ4 EtCXXQteIbGXl4QJIarmypp8K2P+0PnxfIUT3ScPUoj7tOUtlREuhn5LYMwwe0I7TQcL EoUw== 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=ogWh3dYAB/qczfbEkAaaqUWh2MaeasdU2LxmAA1AnSU=; b=y/lUnDJ8Z92vcinY/cwJyzxlKPlpaWLxfqVqcj9qDtaxgFT/yyoIZWQ4+dixDT2QjQ pqdBjnuorhzrHzdqsWmD8yFDy6fAA41Bluy8kurc98lc5phdztquyxXGr3smvUwh5nze kTXOlofLXS5bqhaKrsVj/GsyWAGsHr1YvbjFygCVm4NYYoQARXiqKF1DhVwMh7aTz1zQ wys6Byyo4tzTg0+PQT3FypdFpK6p154s/P+HwNUNuYAx/NQNEsRg/UFkEv6k78EBLkGx vUHeIhEMbxP9HU1ttjgCHIpy0/L7rq7W5Cfist1Y5MmeRcxQdn7iXm4IyohM9dLDHfyx +MnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Iin9d3kt; 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 s9-v6si18693118pfm.85.2018.07.11.00.42.56; Wed, 11 Jul 2018 00:42:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Iin9d3kt; 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 S1732339AbeGKHpt (ORCPT + 22 others); Wed, 11 Jul 2018 03:45:49 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:39587 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726306AbeGKHpt (ORCPT ); Wed, 11 Jul 2018 03:45:49 -0400 Received: by mail-pf0-f196.google.com with SMTP id s21-v6so17886495pfm.6 for ; Wed, 11 Jul 2018 00:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ogWh3dYAB/qczfbEkAaaqUWh2MaeasdU2LxmAA1AnSU=; b=Iin9d3ktrch/m+5hSHCq1o/2GQGTtE650zql3/smMCFtO7rzc0Nozijxi/yW3wX8jL O87hmIFmbxDMPuoPyrPwKj52dXD2biqVOOcO9FexX8pwuIPBsh35QuVWOgt6hx0jxA/L vMQGdyLyhnxToauTw85GYru53bOgX6lGGb9Lk= 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=ogWh3dYAB/qczfbEkAaaqUWh2MaeasdU2LxmAA1AnSU=; b=MQ0j1khDLx0mIjrkJ//0eQ/fSo3CKmofFXUYthY1UUjkl+W0K8wvgpu7NcM7UEmcHs Pjqz0MSwMhvfRhHdz+FA6aNjj3hylwxxuCvkagV7ku8YIFEmoDXNRjw10tC4oU1h2lgf 8a/uFRijxLPOHdaZUuflWioNYrdlL8j8uu1mhYVGAUtXphjC0KBC0LQoEaEC3RXJE6HP yF72gbo2Vw9AWp9YlIbNFP1TEgY6Aq5sYsT7uZjG69dOroocAIzKjBwiDEwNln5dYeU/ I4SfMXfV0aaUDc8AYw47yYOFROibOuNYuRk8Kj6Y+WvoXHuSQVnXKo1f3h4a4GYdr6KR CfMw== X-Gm-Message-State: APt69E0N9WYRY1shtt+OFdTyXAtgdVGNdFry3J+/Z25nejNsIrUeR9s5 ma9LStXo9M9j1gwDAUZrTbRjjg== X-Received: by 2002:a63:842:: with SMTP id 63-v6mr26271279pgi.406.1531294972038; Wed, 11 Jul 2018 00:42:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m86-v6sm40460534pfi.47.2018.07.11.00.42.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:51 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 10/15] arm64: kexec_file: allow for loading Image-format kernel Date: Wed, 11 Jul 2018 16:41:58 +0900 Message-Id: <20180711074203.3019-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch provides kexec_file_ops for "Image"-format kernel. In this implementation, a binary is always loaded with a fixed offset identified in text_offset field of its header. Regarding signature verification for trusted boot, this patch doesn't contains CONFIG_KEXEC_VERIFY_SIG support, which is to be added later in this series, but file-attribute-based verification is still a viable option by enabling IMA security subsystem. You can sign(label) a to-be-kexec'ed kernel image on target file system with: $ evmctl ima_sign --key /path/to/private_key.pem Image On live system, you must have IMA enforced with, at least, the following security policy: "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig" See more details about IMA here: https://sourceforge.net/p/linux-ima/wiki/Home/ Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/kexec.h | 28 +++++++ arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/kexec_image.c | 108 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 1 + 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/kexec_image.c -- 2.17.0 Reviewed-by: James Morse diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 01bbf6cebf12..69333694e3e2 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -101,6 +101,34 @@ struct kimage_arch { void *dtb_buf; }; +/** + * struct arm64_image_header - arm64 kernel image header + * See Documentation/arm64/booting.txt for details + * + * @mz_magic: DOS header magic number ('MZ', optional) + * @code1: Instruction (branch to stext) + * @text_offset: Image load offset + * @image_size: Effective image size + * @flags: Bit-field flags + * @reserved: Reserved + * @magic: Magic number + * @pe_header: Offset to PE COFF header (optional) + **/ + +struct arm64_image_header { + __le16 mz_magic; /* also code0 */ + __le16 pad; + __le32 code1; + __le64 text_offset; + __le64 image_size; + __le64 flags; + __le64 reserved[3]; + __le32 magic; + __le32 pe_header; +}; + +extern const struct kexec_file_ops kexec_image_ops; + struct kimage; extern int load_other_segments(struct kimage *image, diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 06281e1ad7ed..a9cc7752f276 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -50,7 +50,7 @@ arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c new file mode 100644 index 000000000000..a47cf9bc699e --- /dev/null +++ b/arch/arm64/kernel/kexec_image.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kexec image loader + + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + */ + +#define pr_fmt(fmt) "kexec_file(Image): " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int image_probe(const char *kernel_buf, unsigned long kernel_len) +{ + const struct arm64_image_header *h; + + h = (const struct arm64_image_header *)(kernel_buf); + + if (!h || (kernel_len < sizeof(*h)) || + !memcmp(&h->magic, ARM64_MAGIC, sizeof(ARM64_MAGIC))) + return -EINVAL; + + return 0; +} + +static void *image_load(struct kimage *image, + char *kernel, unsigned long kernel_len, + char *initrd, unsigned long initrd_len, + char *cmdline, unsigned long cmdline_len) +{ + struct arm64_image_header *h; + u64 flags, value; + struct kexec_buf kbuf; + unsigned long text_offset; + struct kexec_segment *kernel_segment; + int ret; + + /* Don't support old kernel */ + h = (struct arm64_image_header *)kernel; + if (!h->text_offset) + return ERR_PTR(-EINVAL); + + /* Check cpu features */ + flags = le64_to_cpu(h->flags); + value = head_flag_field(flags, HEAD_FLAG_BE); + if (((value == HEAD_FLAG_BE) && !IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) || + ((value != HEAD_FLAG_BE) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))) + if (!system_supports_mixed_endian()) + return ERR_PTR(-EINVAL); + + value = head_flag_field(flags, HEAD_FLAG_PAGE_SIZE); + if (((value == HEAD_FLAG_PAGE_SIZE_4K) && + !system_supports_4kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_64K) && + !system_supports_64kb_granule()) || + ((value == HEAD_FLAG_PAGE_SIZE_16K) && + !system_supports_16kb_granule())) + return ERR_PTR(-EINVAL); + + /* Load the kernel */ + kbuf.image = image; + kbuf.buf_min = 0; + kbuf.buf_max = ULONG_MAX; + kbuf.top_down = false; + + kbuf.buffer = kernel; + kbuf.bufsz = kernel_len; + kbuf.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; + + kernel_segment = &image->segment[image->nr_segments - 1]; + kernel_segment->mem += text_offset; + kernel_segment->memsz -= text_offset; + image->start = kernel_segment->mem; + + pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n", + kernel_segment->mem, kbuf.bufsz, + kernel_segment->memsz); + + /* Load additional data */ + ret = load_other_segments(image, + kernel_segment->mem, kernel_segment->memsz, + initrd, initrd_len, cmdline, cmdline_len); + +out: + return ERR_PTR(ret); +} + +const struct kexec_file_ops kexec_image_ops = { + .probe = image_probe, + .load = image_load, +}; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index ca00681c25c6..a0b44fe18b95 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -20,6 +20,7 @@ #include const struct kexec_file_ops * const kexec_file_loaders[] = { + &kexec_image_ops, NULL }; From patchwork Wed Jul 11 07:41:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141677 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4800793ljj; Wed, 11 Jul 2018 00:43:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcV9RKCWaUbl/H1T6uKz8FmKRjtRPNf+JKwAGpl/oyGK3m3izSJSq6+OI2Y4PFwsESnDpV2 X-Received: by 2002:a63:5944:: with SMTP id j4-v6mr23790672pgm.222.1531294985034; Wed, 11 Jul 2018 00:43:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294985; cv=none; d=google.com; s=arc-20160816; b=TkJ0Gq++cELWUM+qF3f5ozd3gHDzSGAnLWa19EHnPz83IWHPyRW64bcLbWus6VOZW/ r85MMMAuM6ibEXnVqFKxiWZJ67WKaBvRJV7UfQHm3bkabgzMZ16436+ZbUpEpYmY5CfH iFSVO0Jd69IdzK8EM8+EVLYeQvAJ7gKIrXcshBeBLkxOjme6rWQABTCidUVsoJLqeGzv F0speaDZ1gg7cFclyXEi2FuLdhuh7QQvDIwzyY6CTLr9PZBCt1ntI9u/OOIXGQmPJKIK ymJbrBIjFLygIBJ+SmeYYDsHf7OKVoIaRpnT8+V38Qt8SZ7bMAeBFTYO4VddazCOk++v Cpsg== 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=RcxmasK1UQ66nFR2YeB7D8hx/WTFRWwRJKg54HGY9qY=; b=tqYAngOGgFLfIW9Y589HNfRTXx8MqJ9Jv7H0D5NbJMsKPzfoLxD5JYYyIPJTNRxVJg 489eT+gCmYMO7s4dQD4ELtlKG2T7CSlBXrnwRwJ5kHCojtC0E2Noei6C75Cj0oA/1rQy gBGsJW+DUkNIlsjwDOjw4wt8NcFGiCQUQsoTFo0mLUX7KIjsWTnxIFu3gLyHLlxNw4+X uR6SitZCCJO1BfNlBxcoe3ykEM1qIRnuK93nXJj/hr3cS61AkIL7ma++sRXR8amKjjJz 7lmnmM4ZyeFOqyjkWRuuxbPXOADSf5UegUIM4Ls4W0Oxjn7eSz71bJS3mXhmlp1iDdug TcHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="h/yQmTYX"; 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 i13-v6si5439190pgh.642.2018.07.11.00.43.04; Wed, 11 Jul 2018 00:43: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="h/yQmTYX"; 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 S1732384AbeGKHp6 (ORCPT + 22 others); Wed, 11 Jul 2018 03:45:58 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:39249 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbeGKHp5 (ORCPT ); Wed, 11 Jul 2018 03:45:57 -0400 Received: by mail-pl0-f65.google.com with SMTP id s24-v6so8804620plq.6 for ; Wed, 11 Jul 2018 00:43:00 -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=RcxmasK1UQ66nFR2YeB7D8hx/WTFRWwRJKg54HGY9qY=; b=h/yQmTYX0hKuqb7yAMhcjmC685olIDo+jYSGu2Rta0sGpycgxWKC4dlu1vczw+OQQL DxYLu12M2sYvV9rzraX3JfSk23wG3jNrkiZni4Jean93pJtuJMu0l+nAOOaaGTpC7/Kc 2Wfj5uCYAr6nONpAveqBMlDdHgrjNOMkHiBSA= 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=RcxmasK1UQ66nFR2YeB7D8hx/WTFRWwRJKg54HGY9qY=; b=k/DF0G0IO5cnqVJg2anbwEwBOWbdaDitS39tg0o4nzysD/zJecmWeseSGEKlQr2WyN GIK5+amNX0o0ZBjTVNQfzk1U6Vsat0ugvuCesr029DoU1SpIi/ga1ejZfNEVAzvq9l43 mxq0H/OIV1RVrjVQF4Zcp8BPKgkBgq5fqtggUXeQKzGVzHIxCPrtij72SJB7H0hfDnCt 19/9m/MlevkTTpAosiM1TD0xHBrF/DOjTTZnrH7eLg4uUG6A6Dx+euv3rm6BnoNg6Pe4 ZWVW50osTyCkdak1P7hfHy8Qm2vaCHwFazJ23pBGC+suINB+WLY1jCq6Uka5owD25kYg W4IQ== X-Gm-Message-State: APt69E2l/3c/kpFB4JKvnDwYm/ksXQHbGWxhNUm67SzpwpXArhgwytKP 2rNV9yDHRqcw9ipKHmhw89R3Dw== X-Received: by 2002:a17:902:5381:: with SMTP id c1-v6mr27418061pli.137.1531294980239; Wed, 11 Jul 2018 00:43:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v66-v6sm35520715pfb.84.2018.07.11.00.42.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:59 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 11/15] arm64: kexec_file: add crash dump support Date: Wed, 11 Jul 2018 16:41:59 +0900 Message-Id: <20180711074203.3019-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enabling crash dump (kdump) includes * prepare contents of ELF header of a core dump file, /proc/vmcore, using crash_prepare_elf64_headers(), and * add two device tree properties, "linux,usable-memory-range" and "linux,elfcorehdr", which represent respectively a memory range to be used by crash dump kernel and the header's location Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/kexec.h | 4 + arch/arm64/kernel/kexec_image.c | 9 +- arch/arm64/kernel/machine_kexec_file.c | 114 ++++++++++++++++++++++++- 3 files changed, 124 insertions(+), 3 deletions(-) -- 2.17.0 diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 69333694e3e2..eeb5766928b0 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -99,6 +99,10 @@ static inline void crash_post_resume(void) {} struct kimage_arch { phys_addr_t dtb_mem; void *dtb_buf; + /* Core ELF header buffer */ + void *elf_headers; + unsigned long elf_headers_sz; + unsigned long elf_load_addr; }; /** diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index a47cf9bc699e..df1e341d3a28 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -67,8 +67,13 @@ static void *image_load(struct kimage *image, /* Load the kernel */ kbuf.image = image; - kbuf.buf_min = 0; - kbuf.buf_max = ULONG_MAX; + 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 = false; kbuf.buffer = kernel; diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index a0b44fe18b95..261564df7210 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include const struct kexec_file_ops * const kexec_file_loaders[] = { @@ -29,6 +31,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.dtb_buf); image->arch.dtb_buf = NULL; + vfree(image->arch.elf_headers); + image->arch.elf_headers = NULL; + image->arch.elf_headers_sz = 0; + return kexec_image_post_load_cleanup_default(image); } @@ -38,13 +44,31 @@ static int setup_dtb(struct kimage *image, char **dtb_buf, size_t *dtb_buf_len) { char *buf = NULL; - size_t buf_size; + size_t buf_size, range_size; int nodeoffset; u64 value; int ret; + /* check ranges against root's #address-cells and #size-cells */ + if (image->type == KEXEC_TYPE_CRASH && + (!of_fdt_cells_size_fitted(image->arch.elf_load_addr, + image->arch.elf_headers_sz) || + !of_fdt_cells_size_fitted(crashk_res.start, + crashk_res.end - crashk_res.start + 1))) { + pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n"); + ret = -EINVAL; + goto out_err; + } + /* duplicate dt blob */ buf_size = fdt_totalsize(initial_boot_params); + range_size = of_fdt_reg_cells_size(); + + if (image->type == KEXEC_TYPE_CRASH) { + buf_size += fdt_prop_len("linux,elfcorehdr", range_size); + buf_size += fdt_prop_len("linux,usable-memory-range", + range_size); + } if (initrd_load_addr) { /* can be redundant, but trimmed at the end */ @@ -74,6 +98,23 @@ static int setup_dtb(struct kimage *image, goto out_err; } + if (image->type == KEXEC_TYPE_CRASH) { + /* add linux,elfcorehdr */ + ret = fdt_setprop_reg(buf, nodeoffset, "linux,elfcorehdr", + image->arch.elf_load_addr, + image->arch.elf_headers_sz); + if (ret) + goto out_err; + + /* add linux,usable-memory-range */ + ret = fdt_setprop_reg(buf, nodeoffset, + "linux,usable-memory-range", + crashk_res.start, + crashk_res.end - crashk_res.start + 1); + if (ret) + goto out_err; + } + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(buf, nodeoffset, "bootargs", cmdline); @@ -132,6 +173,45 @@ static int setup_dtb(struct kimage *image, return ret; } +static int prepare_elf_headers(void **addr, unsigned long *sz) +{ + struct crash_mem *cmem; + unsigned int nr_ranges; + int ret; + u64 i; + phys_addr_t start, end; + + nr_ranges = 1; /* for exclusion of crashkernel region */ + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, 0, + &start, &end, NULL) + nr_ranges++; + + cmem = kmalloc(sizeof(struct crash_mem) + + sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL); + if (!cmem) + return -ENOMEM; + + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, 0, + &start, &end, NULL) { + cmem->ranges[cmem->nr_ranges].start = start; + cmem->ranges[cmem->nr_ranges].end = end - 1; + cmem->nr_ranges++; + } + + /* Exclude crashkernel region */ + ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + if (ret) + goto out; + + ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + +out: + kfree(cmem); + return ret; +} + int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, @@ -139,11 +219,43 @@ int load_other_segments(struct kimage *image, char *cmdline, unsigned long cmdline_len) { struct kexec_buf kbuf; + void *hdrs_addr; + unsigned long hdrs_sz; unsigned long initrd_load_addr = 0; char *dtb = NULL; unsigned long dtb_len = 0; int ret = 0; + /* load elf core header */ + if (image->type == KEXEC_TYPE_CRASH) { + ret = prepare_elf_headers(&hdrs_addr, &hdrs_sz); + if (ret) { + pr_err("Preparing elf core header failed\n"); + goto out_err; + } + + kbuf.image = image; + kbuf.buffer = hdrs_addr; + kbuf.bufsz = hdrs_sz; + kbuf.memsz = hdrs_sz; + kbuf.buf_align = PAGE_SIZE; + kbuf.buf_min = crashk_res.start; + kbuf.buf_max = crashk_res.end + 1; + kbuf.top_down = true; + + ret = kexec_add_buffer(&kbuf); + if (ret) { + vfree(hdrs_addr); + goto out_err; + } + image->arch.elf_headers = hdrs_addr; + image->arch.elf_headers_sz = hdrs_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, hdrs_sz, hdrs_sz); + } + kbuf.image = image; /* not allocate anything below the kernel */ kbuf.buf_min = kernel_load_addr + kernel_size; From patchwork Wed Jul 11 07:42:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141678 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4800860ljj; Wed, 11 Jul 2018 00:43:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd6Lg0+O/v+/cy4IZIqZriqL4J6AFo2cfhkmLNihzGVTchss3+Vz4yLJX6NhS6erC/LBYFP X-Received: by 2002:a17:902:b944:: with SMTP id h4-v6mr13180304pls.157.1531294989940; Wed, 11 Jul 2018 00:43:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294989; cv=none; d=google.com; s=arc-20160816; b=yfLv3W3V1E5m1DJX+uTmm/idSfOwem+36V1ylMjrkIyGv1Eo1bosbRMv+02jAWto8y 0roA/9NWBexMT2d4NS5dzmD/f2MAazyMLjqOqRkJ4vvCnVXI1VoVURXPYD1ExPnZAYVh QcfCgVzmGGstey7mkoGgNV95TDgHNvd3FozaTRMZh5HRpfIdR1VrRDH0vAE9a6nSQOyh FOvIEX4LJOC4Y9U+0PxAuKLGawtF/DadcOxb5vA2e2Q3XVfD9G6aTjFluLICgU2ziq0u YOi7y55HopL7+q9G8PL5sVCjVXm/1cYD2zfis1NgRYqwD4hSZ43iyxCi+Jq38yD+UfG6 G4OA== 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=5YjLW+YGwW426KMJWPBoWS6VSrqQYG7x4tImD9v9oZk=; b=btKeV90CBOgF3wR4EE/j88LtGX7o1kIwn6v75Bpyn/ptJeAVFFOKwwCzU0qANcsNw9 ZI5uLkWESB+3ZylKAE/5OzyU9MioabABsLNxTfiZo2SzxWnTl70QoLAmM3FFE0dJTQF/ a3SYFwNf1yhDbmCs+jmh3yNYx/66chgXON1aBZwmfXHQmdfWuuQnEzO1ASg1Mo5x4Dd9 wTs3woVx6rAgRoEdKE+13aTaoZU++qXAcp6UwuBf8KNf0U2lqSDMaUXEnxWj8gufAFzw cH+k5WG3mk+GHwwOV3Rs8Tz6aAAGXeh/uAASwAUqnpLgsWfGbcfZRdBdP138RZ42yojt oSLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bOZexhkd; 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 i13-v6si5439190pgh.642.2018.07.11.00.43.09; Wed, 11 Jul 2018 00:43:09 -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=bOZexhkd; 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 S1732398AbeGKHqE (ORCPT + 22 others); Wed, 11 Jul 2018 03:46:04 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:43774 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbeGKHqD (ORCPT ); Wed, 11 Jul 2018 03:46:03 -0400 Received: by mail-pf0-f196.google.com with SMTP id y8-v6so17865356pfm.10 for ; Wed, 11 Jul 2018 00:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5YjLW+YGwW426KMJWPBoWS6VSrqQYG7x4tImD9v9oZk=; b=bOZexhkdcZ5Jx8wKJM/Vsenfu7c8macbqO3b5wEOx3DecVIaCnLDtNFLnpU2JjDI1i /1hnYZYWqAbqQbnE5KnpJkJweTr/OgmAJNjfSNHqwqallzdDWxml/XMKsA0+W1Mej7w2 ujJ3x+L/uNdOJdgvlaNMGmd0XKks2XxtYVOKk= 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=5YjLW+YGwW426KMJWPBoWS6VSrqQYG7x4tImD9v9oZk=; b=KQZKqmmtoJgi1eNVKH93rwucE6PqykcN5/wfRYpKftED+7lCVLg7LVIGcnslZFCnl6 S8PQJJXGj1fuyxP0g6Drj7KCfKtaV3mXnsX6XyIx7Irs5T7dN1Dmo3jrYNcQjG4ENJ8W OdNMrgf+vLOnhdMz2reqpPeUddQ1F0JJpvV3XKgfNAyx3IbnZ5rZUq7fjNHTKlm/UV9R il3QlIKtKkD8rmzCdfJlLrXDcbkSwMncb2JYOZbxS1J1iser2iEXB4A7HKvw2dV5wXlN f57k1FppJ9bvDz2hz1HwQjipZRzwYyrqGwCJe6vvBCmIDJWlmv/czmbOLaTobfTvZV3g ULnw== X-Gm-Message-State: APt69E3KODbZ2ZGZ9QA8IBuvbVyTsLgyn1yj54no2UKpHoNlr6sOHqrW dqWUoeFvnJdXbO+CinFOgJK7Pw== X-Received: by 2002:a63:4763:: with SMTP id w35-v6mr25331001pgk.140.1531294987181; Wed, 11 Jul 2018 00:43:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m134-v6sm29576212pga.20.2018.07.11.00.43.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:43:06 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 12/15] arm64: kexec_file: invoke the kernel without purgatory Date: Wed, 11 Jul 2018 16:42:00 +0900 Message-Id: <20180711074203.3019-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On arm64, purgatory would do almost nothing. So just invoke secondary kernel directly by jumping into its entry code. While, in this case, cpu_soft_restart() must be called with dtb address in the fifth argument, the behavior still stays compatible with kexec_load case as long as the argument is null. Signed-off-by: AKASHI Takahiro Reviewed-by: James Morse Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/cpu-reset.S | 8 ++++---- arch/arm64/kernel/machine_kexec.c | 12 ++++++++++-- arch/arm64/kernel/relocate_kernel.S | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) -- 2.17.0 diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 8021b46c9743..a2be30275a73 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -22,11 +22,11 @@ * __cpu_soft_restart(el2_switch, entry, arg0, arg1, arg2) - Helper for * cpu_soft_restart. * - * @el2_switch: Flag to indicate a swich to EL2 is needed. + * @el2_switch: Flag to indicate a switch to EL2 is needed. * @entry: Location to jump to for soft reset. - * arg0: First argument passed to @entry. - * arg1: Second argument passed to @entry. - * arg2: Third argument passed to @entry. + * arg0: First argument passed to @entry. (relocation list) + * arg1: Second argument passed to @entry.(physical kernel entry) + * arg2: Third argument passed to @entry. (physical dtb address) * * Put the CPU into the same state as it would be if it had been reset, and * branch to what would be the reset vector. It must be executed with the diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index f76ea92dff91..830a5063e09d 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -205,10 +205,18 @@ void machine_kexec(struct kimage *kimage) * uses physical addressing to relocate the new image to its final * position and transfers control to the image entry point when the * relocation is complete. + * In kexec case, kimage->start points to purgatory assuming that + * kernel entry and dtb address are embedded in purgatory by + * userspace (kexec-tools). + * In kexec_file case, the kernel starts directly without purgatory. */ - cpu_soft_restart(kimage != kexec_crash_image, - reboot_code_buffer_phys, kimage->head, kimage->start, 0); + reboot_code_buffer_phys, kimage->head, kimage->start, +#ifdef CONFIG_KEXEC_FILE + kimage->arch.dtb_mem); +#else + 0); +#endif BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index f407e422a720..95fd94209aae 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,6 +32,7 @@ ENTRY(arm64_relocate_new_kernel) /* Setup the list loop variables. */ + mov x18, x2 /* x18 = dtb address */ mov x17, x1 /* x17 = kimage_start */ mov x16, x0 /* x16 = kimage_head */ raw_dcache_line_size x15, x0 /* x15 = dcache line size */ @@ -107,7 +108,7 @@ ENTRY(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, xzr + mov x0, x18 mov x1, xzr mov x2, xzr mov x3, xzr From patchwork Wed Jul 11 07:42:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141679 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4800955ljj; Wed, 11 Jul 2018 00:43:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeg9eYyGurNknopeAMD/8P5S6GtU8qaEQ46QNHX/Ro4OtgvpiOFLjQVq/h/4vwmwDGi7TRE X-Received: by 2002:a62:9652:: with SMTP id c79-v6mr29152362pfe.114.1531294997942; Wed, 11 Jul 2018 00:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294997; cv=none; d=google.com; s=arc-20160816; b=iRHsgW96iTJCz8XN8Q+5N0KZEG8KDeHZkce0/jQ6+6jxBxS6JS3Mz03V0gJVXzCFov 4jrlU8vi2WuGIMBP23szcGyfWnAFKGNz+g6+DUqA81GeZMLjxwUoaY8lrrNkUaU3B9/m kE0V5NC8VqijeEwXLCfDBGS5YnwkvJNRkFHfM2AlWisOo3HaIQCGn5gmsB05NyniCWKc 7ooEsjQT1y8dW+A62d6xMOGNRp4MA5KkEuFM7w4M3wtt7Ufw29QsJmYZGGE7uXoo/tDs 7T2UvpFcG+eJqIqGWTaqSzDoSk1F6BB3PpNg+XzS/XTPAQvseQwHv5KVtWU+tCRTms2K n8nw== 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=udBD3FA/hkAWhAoznOJdhSIXwaGNnm+w3oMPbyzv9VI=; b=boKX7xyyjPvvrJm9CuN7wSYM3JkAadTdJaSQ+SChmzlPQLsq91T8dK+gq0S011VcDK p2eXmJFBR3Ok+sn81FrJ3JzWjUhbFkO2SrymH0JCwFFJ5HPnQif0DK9y72Vnal0tYlSd LZ4/+jE93yWJ10NnRTv1Y46fut+Ex0dIKZfLZ2a8K33QIRNuAw4B2cvCaejeq9vRJHPB 4Wcuwvlt65idTVqTP+xgK8UZ3bfC5XUKcf/vHXiqyG+6Rz6Xc8r5vJwd8ZGoFmXaQE2Y yTL9Gkg89NqDq4NHbNN2ISBvow6NmdjsJrQKi4+O01yQY0B8YLNaHSZGtnw9zptMqpSp I+Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DDS3bvvN; 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 i13-v6si5439190pgh.642.2018.07.11.00.43.17; Wed, 11 Jul 2018 00:43:17 -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=DDS3bvvN; 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 S1732404AbeGKHqL (ORCPT + 22 others); Wed, 11 Jul 2018 03:46:11 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:42384 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbeGKHqK (ORCPT ); Wed, 11 Jul 2018 03:46:10 -0400 Received: by mail-pl0-f68.google.com with SMTP id f4-v6so4607119plb.9 for ; Wed, 11 Jul 2018 00:43:14 -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=udBD3FA/hkAWhAoznOJdhSIXwaGNnm+w3oMPbyzv9VI=; b=DDS3bvvNhkJvcyqdwc1EFKAG41UgqJWBEUWNzUomCGlSVBYybxbPWOYB6U/HJkrtI+ JO922kw8K9fFwwQ7Xx4GUuIiEBLkFOp97E/qUZUTrMLS2ZvIya6FSNsz3wkun19dQeD2 7ktTYhWtLCQlRYy6zi3kfQtakAzPYqwr24TQA= 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=udBD3FA/hkAWhAoznOJdhSIXwaGNnm+w3oMPbyzv9VI=; b=ZEHhVLSQLph3xV3uuRjbBA8tEowSZ/+Hcxx790Ly224q6+cVMKthvKURY/8u6CDXdB dnFbBOjjSrUhHwcZpGTAZJSonaYhWuQrucD0Oj4J+4lcO+w2zeGJizr4phkhhxgiXR0B IRHOvDKJstkpYCyXK4IO16+RuNDg/0a43WpsasEzFlIHOXlfGstsaDehU3B1D1zbWOgp 8DF4YCrhBLNg2dVpSMrYkzgGOZo4yDPpn2HtfUWhEPC0bV6ZBV1wAAMbnIxI8iK2TNeF NmMOFaUZPKfsNSnNnIQ0MnHNKvQ5CBgUtCOok7BvZXC3rMUq2g7kJw1DMEmt3XVfdqy6 j+dg== X-Gm-Message-State: APt69E2E2tZMtxhT/Xz5EVGoLxsQO1YS/jOebCXAQ0UcNVAUKw1CwWBl EEEaFXdzIWs5XE7ypZ7R9bX8Gg== X-Received: by 2002:a17:902:8ecb:: with SMTP id x11-v6mr28387294plo.308.1531294994256; Wed, 11 Jul 2018 00:43:14 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m86-v6sm40464859pfi.47.2018.07.11.00.43.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:43:13 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 13/15] include: pe.h: remove message[] from mz header definition Date: Wed, 11 Jul 2018 16:42:01 +0900 Message-Id: <20180711074203.3019-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-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.17.0 diff --git a/include/linux/pe.h b/include/linux/pe.h index 143ce75be5f0..3482b18a48b5 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -166,7 +166,7 @@ struct mz_hdr { uint16_t oem_info; /* oem specific */ uint16_t reserved1[10]; /* reserved */ uint32_t peaddr; /* address of pe header */ - char message[64]; /* message to print */ + char message[]; /* message to print */ }; struct mz_reloc { From patchwork Wed Jul 11 07:42:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141680 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4801029ljj; Wed, 11 Jul 2018 00:43:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdL44vJK/a09qPkLPzGfyph+FbgvCzJKBHKQpKJCKMx0wRsLnwobhvroAmLglCWusLqsuDm X-Received: by 2002:a65:6455:: with SMTP id s21-v6mr18965013pgv.394.1531295003992; Wed, 11 Jul 2018 00:43:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531295003; cv=none; d=google.com; s=arc-20160816; b=guDiUAPKtA/aRI6TI/vw1yhcPLisQqPhkBH/+hJ+eW1skYlLY+bbByhzu4Tmhb5FWl c7krqn5qZdEFvpfa5rWvz6J9j2awg0876RrdekQlnFMunVQPaXSrmr/BrYm3UAWXOWEs 0KBwHa24yiydR+fhn+iIs4BwGqZnqxLbQbYg2IfSTERca9FuSjvJbRF66FrmfJ3hYsJR NlQ3HQnfpLTSW1KC4dS45XhHyHDVfSqe+3knYL1LeiVMJIfh5/5vtWN9j10r1Xtu4JuG pW3NqKy9ty+FCD0wkotXlbhLwlEGS0oBJZ1MzgRs7LUetUK+ISNBFbTyZjUoxAqTF4jc oTDw== 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=IhXU1taVFqTvONKqzouhydG5S7Jk/KaBxJ/e0+WeXgw=; b=VQmXDWtC5UGPUKKOLs127oHm2BG0wVDDV9Tx8Q7YXTiqf5dpNeZG9Qh0v/+X4GbIGz 9g3B/QA7MO3uU0xvi/fi74VUo7mjM7Zh6auP1dj2WrtnDNPk7DeuvxpHZLJ1tkbGtw5z 5EfA45EZR3WLy+HoF1iXMkWzqFgH+8fLIUOcZp7awEktDzkxeMkLKaYVRuIaCWl+tLdd dtnA8t82+oOwfhi4v0BwoDmjVMzn9M6RYBRiynECNcO/nLiguxI12rM8E1AQNJ2wo+h6 3mBEtxbDjOxyrO071g1Hr54V/5EyGBQ+AF8H+14YIaRBXSK9tts9Uv0thwodybPbkRvp WZqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eekxUjV2; 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 c16-v6si14522434pfj.333.2018.07.11.00.43.23; Wed, 11 Jul 2018 00:43:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eekxUjV2; 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 S1732412AbeGKHqS (ORCPT + 22 others); Wed, 11 Jul 2018 03:46:18 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:42220 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726289AbeGKHqR (ORCPT ); Wed, 11 Jul 2018 03:46:17 -0400 Received: by mail-pf0-f194.google.com with SMTP id l9-v6so6238943pff.9 for ; Wed, 11 Jul 2018 00:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IhXU1taVFqTvONKqzouhydG5S7Jk/KaBxJ/e0+WeXgw=; b=eekxUjV21HslWOHRESAr06L0Kztm+FKq2OFDkoPcAr+yWsaGuXIQFf2ChsDETAo8V1 kdb+Qd7+i9Kq0EobklijY/i+iCpJ3ba5J8KWnrVcEA2ey8ZR6QZFOpqTtcjrq96yRDja 8sGI6sSDNFbVpnDPOYLscJ+dPMmD/gsZr2RUU= 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=IhXU1taVFqTvONKqzouhydG5S7Jk/KaBxJ/e0+WeXgw=; b=D9MB0U9Xw3lGkIDtUGUCwxvahk0nxHjniZ6cuWk9TvDVYzFgP6kDVyAef1pS3t+Axu a1Oo0XVf57Q8a8MYO/Q4s4AcWDMiMisj0azGBn5P8230gr7iUnG2EIhzchNFos1n9Owk ZYE1T+luElsS2/yplc5asYO/9dQIgh9FJJntXLNzoQGIBROSEzESsgdtESpqyBsWhHy+ dcvvR3wul9p6cTrxuuGl94xMznqT873sYEW+lYDDFAuNG/NtVGCKO0Vi+y4+JszGoBli f+g5bqkkgER3JD5vjQIm6w9DiBMAKov6XgIs9IoBh8e0UbBMz2+UXYo8Rgp3MKIOQ+SX nS8w== X-Gm-Message-State: APt69E2LksjPPIkUUFAPEGBFhf1tuaoNdxNWGSfNHHeQhKR1ZaxgOz4h Ei7VVF+YTT5bmmcHKfrhTq7lVw== X-Received: by 2002:a62:ec41:: with SMTP id k62-v6mr28760983pfh.206.1531295000777; Wed, 11 Jul 2018 00:43:20 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w123-v6sm33118200pfb.38.2018.07.11.00.43.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:43:20 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 14/15] arm64: kexec_file: add kernel signature verification support Date: Wed, 11 Jul 2018 16:42:02 +0900 Message-Id: <20180711074203.3019-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With this patch, kernel verification can be done without IMA security subsystem enabled. Turn on CONFIG_KEXEC_VERIFY_SIG instead. On x86, a signature is embedded into a PE file (Microsoft's format) header of binary. Since arm64's "Image" can also be seen as a PE file as far as CONFIG_EFI is enabled, we adopt this format for kernel signing. You can create a signed kernel image with: $ sbsign --key ${KEY} --cert ${CERT} Image Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Kconfig | 24 ++++++++++++++++++++++++ arch/arm64/kernel/kexec_image.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+) -- 2.17.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index a9a3a5583c8b..1445eb2fc833 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -844,6 +844,30 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config KEXEC_VERIFY_SIG + bool "Verify kernel signature during kexec_file_load() syscall" + depends on KEXEC_FILE + help + Select this option to verify a signature with loaded kernel + image. If configured, any attempt of loading a image without + valid signature will fail. + + In addition to that option, you need to enable signature + verification for the corresponding kernel image type being + loaded in order for this to work. + +config KEXEC_IMAGE_VERIFY_SIG + bool "Enable Image signature verification support" + default y + depends on KEXEC_VERIFY_SIG + depends on EFI && SIGNED_PE_FILE_VERIFICATION + help + Enable Image signature verification support. + +comment "Support for PE file signature verification disabled" + depends on KEXEC_VERIFY_SIG + depends on !EFI || !SIGNED_PE_FILE_VERIFICATION + config CRASH_DUMP bool "Build kdump crash kernel" help diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index df1e341d3a28..bb0a95add197 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,9 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len) !memcmp(&h->magic, ARM64_MAGIC, sizeof(ARM64_MAGIC))) return -EINVAL; + pr_debug("PE format: %s\n", + memcmp(&h->mz_magic, "MZ", 2) ? "no" : "yes"); + return 0; } @@ -107,7 +111,18 @@ static void *image_load(struct kimage *image, return ERR_PTR(ret); } +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG +static int image_verify_sig(const char *kernel, unsigned long kernel_len) +{ + return verify_pefile_signature(kernel, kernel_len, NULL, + VERIFYING_KEXEC_PE_SIGNATURE); +} +#endif + const struct kexec_file_ops kexec_image_ops = { .probe = image_probe, .load = image_load, +#ifdef CONFIG_KEXEC_IMAGE_VERIFY_SIG + .verify_sig = image_verify_sig, +#endif }; From patchwork Wed Jul 11 07:42:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141681 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4801178ljj; Wed, 11 Jul 2018 00:43:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpejYZkVwmRpWBMCv+9TeWmkFl6PkW50g6Dvm09OS97aEUz6rOcZ949EMEZD1K/70u7yvzk0 X-Received: by 2002:a17:902:a989:: with SMTP id bh9-v6mr28232122plb.245.1531295015293; Wed, 11 Jul 2018 00:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531295015; cv=none; d=google.com; s=arc-20160816; b=tGqtvK6jMRvm+OPI/w97rG6ULVCg9bmnOI8Xtceofp7vaRtTfbT8VWVwYP5RRFl3R5 DhNmtN3W/ALLcsBJerUhNIWGrgbE3LyuJwugEf59F6bVKjWz2We2+yCwrg36/V+IPCz8 s93VZ0Jb3hCy78DHagh3ThLigAolq7fiL6GibD56J7f/8ogByh32GxXnjg6kl/a8Wd8k yn5iem7bA/SJ8UhbyPr2OVn0pWTrz4yJJiVzzcWHO6BXXSy1HBwCBu+iaYYTyVnpgOfz 99c4sSt2mOdm9sfhTCqpTZ+X7QDzzwP1p9Ph+PPVClXyz2cXjpBVVRBPedGabHWX75Ad UVdA== 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=uQoziQZkHVnlrNNUZNXAOepb9dTdnP1dZcnkI2L9pzA=; b=k/FweTK7aD6tjAsEEKVDsHyEF1tCFHZ0SVj3YHJY0RWfbLMFSOpzeXi10g+h8lKooT fIEMh30mHn+Mxum2HWiIl8ILo5diWCUsD3HOVX7SdJYoRmFpE4+yramSwlr/5g3LWDuN ZAIoF18dxSDBIXqS0A4fzoPbwjRYwvEgqry6p1+oAmsJ7k+RjlDwsjcVdvN5eNCJOkaE BYCP5ggp6WjdDXeij0HSGxACMw6wtdwMRj/RbYN7JsnHIoTwsH2b+7PfhHaHCMso+HNr +gYbNCXuczGOqO1U0YPyiZi+6MAUB0dsvo8ekEv+YKRQuNSYeCdO5JPQjmRlvzq0wiiw ua1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SIE6TkGL; 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 u1-v6si17319142pgp.18.2018.07.11.00.43.35; Wed, 11 Jul 2018 00:43:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SIE6TkGL; 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 S1732418AbeGKHq3 (ORCPT + 22 others); Wed, 11 Jul 2018 03:46:29 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43831 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726289AbeGKHq2 (ORCPT ); Wed, 11 Jul 2018 03:46:28 -0400 Received: by mail-pg1-f195.google.com with SMTP id v13-v6so2688364pgr.10 for ; Wed, 11 Jul 2018 00:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uQoziQZkHVnlrNNUZNXAOepb9dTdnP1dZcnkI2L9pzA=; b=SIE6TkGLdOsMdh5DXKeCj9XxFa424kGQP+vU592YrheWapegYtykabNa2h6p3Z7ZF+ uzo2EzV2GsH+kHAU04n4Co1PZrY9NY8bZywVXdpjE8EK1OWGKT6nzGW0sVsj0dm4VnMg 1ag1YVyppqMmEmMrgjDIGpJscQzPOylYVhunA= 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=uQoziQZkHVnlrNNUZNXAOepb9dTdnP1dZcnkI2L9pzA=; b=GgFx9ZfccxLCoTc8OoASTjmTZ+kdofG7jXmZ/VcVs0zDHCaHJnjURhapPp1LZJ82PT bRLcn4RCPeCP+BQy5cay6LqeD9CdQS5nmbKpmXgxS5BSZcAxepdRLKT8AYk9qsN3gy2J JG7rI6zNkBSPyfaNbENrtHxWLNiurT27cGF+qPow3CWKv7Mbwmfx7+iYHTACnrUL2Ril a00Bp0huXGztkE8JowLB+WAE6f/YUGFweTTYI8FDPS94bCDYdA357P2ya5zoSmTlWtt3 iwb8B+uD4nNaKepxhFGiEhMFnjlg82RaIhKWk7LcwPhjh2Re4jNXF31fcxx/153hQizy I+6g== X-Gm-Message-State: APt69E14g/suSkmjd1riOA1JMGKTDMHgHxd0WgObhoRwaOIrcr9PLiQX Y9j/wZgyo3lvakR4mWCwHfR1KQ== X-Received: by 2002:a63:f:: with SMTP id 15-v6mr19477044pga.430.1531295011680; Wed, 11 Jul 2018 00:43:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v17-v6sm23357015pfn.177.2018.07.11.00.43.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:43:31 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [PATCH v11 15/15] arm64: kexec_file: add kaslr support Date: Wed, 11 Jul 2018 16:42:03 +0900 Message-Id: <20180711074203.3019-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding "kaslr-seed" to dtb enables triggering kaslr, or kernel virtual address randomization, at secondary kernel boot. We always do this as it will have no harm on kaslr-incapable kernel. We don't have any "switch" to turn off this feature directly, but still can suppress it by passing "nokaslr" as a kernel boot argument. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/machine_kexec_file.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.17.0 diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 261564df7210..99d771afe88e 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -161,6 +162,12 @@ static int setup_dtb(struct kimage *image, } } + /* add kaslr-seed */ + get_random_bytes(&value, sizeof(value)); + ret = fdt_setprop(buf, nodeoffset, "kaslr-seed", &value, sizeof(value)); + if (ret) + goto out_err; + /* trim a buffer */ fdt_pack(buf); *dtb_buf = buf;