From patchwork Thu May 16 10:28:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 10946299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0D93924 for ; Thu, 16 May 2019 10:28:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE516288F8 for ; Thu, 16 May 2019 10:28:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1D3E28978; Thu, 16 May 2019 10:28:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0ED94288F8 for ; Thu, 16 May 2019 10:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=6uKkUNUsqam9w05gA8n41TjUoguLGdjFkeQQK+9BC4k=; b=cembi6hEfg9WYo Nol+wAWbdAIW9sBc+hejuKXzxzVlpFqyLxlgyEU6Csz0Tr4+SGwny5kBrtMBU9wcxGZX/pzAVe0FV P0zRZRDJFQWLz+rV3Sgn0v3kpjKF3tWCduh/d8zmNYtQZfX4islEcpF7/F/Swdpq0k3eNWLKWbgoy arcBxLoOhzyh74ubbktjs61lHluf3hkhBunTgVeCHiA1M12sYHzG6vr92XUd5PWYP8aEENfGHNnMo QywAGOVjaqQvXlWoDEQVH+91/OctItfCc8w+Qe4nFExUD3i+ZgGn3jvRpe3bdM51CT0C+A5W54YaV XXZ8e5+krmPiBnC5iVew==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRDcu-0001gm-DS; Thu, 16 May 2019 10:28:40 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRDcr-0001fy-76 for linux-arm-kernel@lists.infradead.org; Thu, 16 May 2019 10:28:38 +0000 Received: by mail-pf1-x444.google.com with SMTP id u17so1621959pfn.7 for ; Thu, 16 May 2019 03:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zdJ9wOciRCFBg5OhP24ccEPW98TzZ5e0I9CMtzhtP7k=; b=j6TjZjdTvdf6CjCSc4yUwh0w3lHoZrsZkToyITUvilzaKO5fJ0vqwlISOAS2BDbhb6 2VbC5h3lCINUHea8eLr5qB7bqHliBCV26+cZHkuc6/kN9BvyoxdDK0mVitXKri3MUivK IbYPCZMbdWKCRDRF9dlx5fQMu94ziC7y43FQI= 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:mime-version :content-transfer-encoding; bh=zdJ9wOciRCFBg5OhP24ccEPW98TzZ5e0I9CMtzhtP7k=; b=HNzH/YzdwsqUZhEtXl9yrye8DPxFKWE7fngxy16VKhSz+E0mPu7bazRRhvU/aNSuGT LflrrlITdf9xJydrTn0fC+uMBRl2zYLxHb5wr4REeLnrWT8x08iQGyFaLAR9j8SfJ/Pz IDZX1K6KSlMYx2BPFLa38RRVkurr7/OjrNLnoQ29M+RoXqd3Z+ovlQzR68mi2p875QiG ttoj/u8YmJJcwvVXDTzkGk/A7+Yu2x60FBdOOyterUzYFSZlmW/3CKGrCLWx1XWyC0Ui 6BPrr8GIXj6TAoGZhtHEisStcsr3nCqKJo6+1U63FfnzaQKW7HuOplZor8ETW4tFqn+a IlUg== X-Gm-Message-State: APjAAAUjJjjc5rvjwJuNGN+OvIF5VcLyYsLXbhNRavVGzo/toMNi0GYX eG2kPx4DsKqgwyVmmjWCBwLGVgY0H4U= X-Google-Smtp-Source: APXvYqzPTskZH8eYovOCQmHUvgMMgQkqepD4OYCnKFG7nHyDLIhQaMeOn+J/Ld+Xt/Ggq8IM/7Zmkg== X-Received: by 2002:a62:e00e:: with SMTP id f14mr52831963pfh.257.1558002515484; Thu, 16 May 2019 03:28:35 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:b852:bd51:9305:4261]) by smtp.gmail.com with ESMTPSA id h123sm9338048pfe.80.2019.05.16.03.28.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 May 2019 03:28:34 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/3] include/of_fdt.h: add a weak arch hook to update fdt pgprot Date: Thu, 16 May 2019 18:28:15 +0800 Message-Id: <20190516102817.188519-1-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190516_032837_281703_E9048A90 X-CRM114-Status: GOOD ( 12.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Yu Zhao , Kees Cook , Ard Biesheuvel , Catalin Marinas , Stephen Boyd , Chintan Pandya , Will Deacon , linux-kernel@vger.kernel.org, Mike Rapoport , Jun Yao , Miles Chen , Rob Herring , James Morse , Hsin-Yi Wang , Andrew Murray , Andrew Morton , Laura Abbott , Frank Rowand , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Does nothing as default, arch can implement their function to map fdt to RO/RW. This is convenient if arch map fdt to RO during init but needs to write fdt in some special cases after that. Signed-off-by: Hsin-Yi Wang --- drivers/of/fdt.c | 13 +++++++++++++ include/linux/of_fdt.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index de893c9616a1..e84971d1e9ea 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -30,6 +30,19 @@ #include "of_private.h" +/* + * update_fdt_pgprot - Arch hook for changing fdt pgprot + * + * @prot: page protection flags for fdt + * + * Architecture can implement this function if they want to chagne + * fdt page protection flags before or after doing modification and + * fixups to fdt. + * + * Default does nothing. + */ +__weak void update_fdt_pgprot(pgprot_t prot) {} + /* * of_fdt_limit_memory - limit the number of regions in the /memory node * @limit: maximum entries diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index a713e5d156d8..406c3e7b2b75 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -109,5 +109,7 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +extern void update_fdt_pgprot(pgprot_t prot); + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_OF_FDT_H */ From patchwork Thu May 16 10:28:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 10946301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEE091395 for ; Thu, 16 May 2019 10:29:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC307288F8 for ; Thu, 16 May 2019 10:29:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF59728978; Thu, 16 May 2019 10:29:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 66299288F8 for ; Thu, 16 May 2019 10:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MnsZrCavNE6+LsqpvzW6lSEYdTxpjmQvdFBk61Ey+5Q=; b=kbY6p3xxo8PZ1c XQFxYV1ay97VCScTdO9fKy1hzHOvZ2xTRHqNxILLEihIIXrmp3nueYzm9a/yqoiExHRTQmwxVBgUs wXfizVN/op1Fgh8S4ws8ZJecLdslJGa7FO9FWy93pedLNzawyt7F6MCkuG4uZp5ea4oYYW3LHBJYi q32lG7VG49CMd9ovKJQMw4ZfiiWaYwPx10YNd0ltXY8pRiEixNMz41hzzSWqt9I+SUzO2jKMB642h 39SinS1Ss1I+XWjFLL1qKolivJKBEbCvzmd9fuMq+Eblf5sj0snASv9sKSYOHfEpB/dJOYIYLBVUa JaweCZSr9AfX1UZyg59A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRDdA-0001wb-FC; Thu, 16 May 2019 10:28:56 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRDd6-0001uw-M0 for linux-arm-kernel@lists.infradead.org; Thu, 16 May 2019 10:28:54 +0000 Received: by mail-pl1-x644.google.com with SMTP id c5so1400631pll.11 for ; Thu, 16 May 2019 03:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g6nTVnaTPu6u0ik4+YTeRCBKr6f5B4jeaBgRZ5SbxTw=; b=ZQ/kc6aBkZflGhXSDxDpSNRqmjhb6N9q0F7lksh1UBLl2/I6uLpMJ2EFTj5RVV6ZxA IcqVwlZFK1fgG3i5YsdnWHnSvAe8T4bmzMowpcI9tL+lc9gEd+w3HwFB2PVGkTmHiNqw kznERwYCaREsUwnxdTq4nxj3gvx3GkByAOgng= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g6nTVnaTPu6u0ik4+YTeRCBKr6f5B4jeaBgRZ5SbxTw=; b=qLFfsCQ48bxtItLTJglgEaxioTo+hcuwcwQryHHnkj0QaZVBk/sPXudSd9XW5vyPR0 qfTH+phtqIo1d6U244QBgPpsCkECWlrW9VBg7VvzI5017pkSn2mBaGZuzZDWpe8IbPd/ yWDm3zNG26jPo1P/2nrf/PGha/+q75gE4153y5oniMYQ9TwxUWF6kDUpgz3LrCnP7vO1 cy5iz3oxgIGDjGVnQHuyqs3HgBTq6Gt6cg3gMv5BmwijRBUXPWkVrvq79l7MisAlqEVB cf7x6Is/8OY2umueAnR0BlwvOCiqj4OjagLspyqx0ss29AONRTaHe9P27UMGxiFhWEQ+ FT1A== X-Gm-Message-State: APjAAAVjh6m45lEnWoQsJluJ0U3tpSNYOMUkN432pQ27UA21UTy6Q88q LpYmDq8LDb/BAN97xs8WDeptdimWQjY= X-Google-Smtp-Source: APXvYqz6D4VCan2gvNE8/0EMna/+ZpJBgnCigTNFcMqpDIsMc91bUoTxMOxk4U2jcWrjaJnlZy8LoA== X-Received: by 2002:a17:902:9a81:: with SMTP id w1mr47668258plp.71.1558002531758; Thu, 16 May 2019 03:28:51 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:b852:bd51:9305:4261]) by smtp.gmail.com with ESMTPSA id h123sm9338048pfe.80.2019.05.16.03.28.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 May 2019 03:28:51 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/3] arm64: implement update_fdt_pgprot() Date: Thu, 16 May 2019 18:28:16 +0800 Message-Id: <20190516102817.188519-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190516102817.188519-1-hsinyi@chromium.org> References: <20190516102817.188519-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190516_032852_717287_06C7342C X-CRM114-Status: GOOD ( 14.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Yu Zhao , Kees Cook , Ard Biesheuvel , Catalin Marinas , Stephen Boyd , Chintan Pandya , Will Deacon , linux-kernel@vger.kernel.org, Mike Rapoport , Jun Yao , Miles Chen , Rob Herring , James Morse , Hsin-Yi Wang , Andrew Murray , Andrew Morton , Laura Abbott , Frank Rowand , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Basically does similar things like __fixmap_remap_fdt(). It's supposed to be called after fixmap_remap_fdt() is called at least once, so region checking can be skipped. Since it needs to know dt physical address, make a copy of the value of __fdt_pointer. Signed-off-by: Hsin-Yi Wang --- arch/arm64/kernel/setup.c | 2 ++ arch/arm64/mm/mmu.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 413d566405d1..207cbb5f7965 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -66,6 +66,7 @@ static int num_standard_resources; static struct resource *standard_resources; phys_addr_t __fdt_pointer __initdata; +phys_addr_t fdt_pointer; /* * Standard memory resources @@ -292,6 +293,7 @@ void __init setup_arch(char **cmdline_p) early_fixmap_init(); early_ioremap_init(); + fdt_pointer = __fdt_pointer; setup_machine_fdt(__fdt_pointer); parse_early_param(); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index a170c6369a68..196ab4d9e92a 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -953,6 +954,22 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys) return dt_virt; } +extern phys_addr_t fdt_pointer; + +/* Should be called after fixmap_remap_fdt() is called. */ +void update_fdt_pgprot(pgprot_t prot) +{ + u64 dt_virt_base = __fix_to_virt(FIX_FDT); + int offset, size; + + offset = fdt_pointer % SWAPPER_BLOCK_SIZE; + size = fdt_totalsize((void *)dt_virt_base + offset); + + update_mapping_prot(round_down(fdt_pointer, SWAPPER_BLOCK_SIZE), + dt_virt_base, + round_up(offset + size, SWAPPER_BLOCK_SIZE), prot); +} + int __init arch_ioremap_pud_supported(void) { /* only 4k granule supports level 1 block mappings */ From patchwork Thu May 16 10:28:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 10946303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02AF9924 for ; Thu, 16 May 2019 10:29:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF658288F8 for ; Thu, 16 May 2019 10:29:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0DDD28978; Thu, 16 May 2019 10:29:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 00140288F8 for ; Thu, 16 May 2019 10:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Xlhe2qwtLykQ5F9uoP1wsF3GciRt+qUurLp0AClKlds=; b=uqdSss5EsdhamN iMdPb1NxO2PxvxM8ITp1B09z+4UtVnIlGO3tXvrFwlbcRT/VrtTxDrhJeqTb4rZAuJ/i61t+LvEs6 WHB9nq5UHNb2QU8B7h2AcCsRy14fYDZHX9TZGpm+fpi+wydAQqL0AKmOdNAgrKOf7nGQbbu6LYX4q 8PoZzxzkcwgUdVw79biBsWfsqOqfnfKfAnw+L7Qxc6pUyThfSbw0O/93pMjD3zoOIdkDeFgiyx8+Y CNrc5FRGfZ2XEoHxfMXvMUkm9uINnE6k7QAZsg2rBSrVxDXvako3Nixz5Z5aSkmttg5NVQ1NiQXK2 0dWaFfaDLZ3dPzRJ5gFw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRDdK-00029n-8s; Thu, 16 May 2019 10:29:06 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRDdC-0001zC-Uw for linux-arm-kernel@lists.infradead.org; Thu, 16 May 2019 10:29:03 +0000 Received: by mail-pf1-x441.google.com with SMTP id z26so1624967pfg.6 for ; Thu, 16 May 2019 03:28:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MnHxDH7/gQC7S9Ex4Yrjn2JKssZnvEJdzim34WmQ+q8=; b=Q7r9C3C+1xp3K+F79f6HS9pMPjdOXBJlhNlNH1sNo8Gf28sq+UxJPIbw2WS+1yYLw6 yZqgEDWASIraQfHYA0liC/dDovipJoQ9hzXfSk4dtix+XDB4gYK6M8Y3wfvVbl2uYTjW uf+2pUVkJmyMR0yFOwkMZUe0h831zzwbPUIRs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MnHxDH7/gQC7S9Ex4Yrjn2JKssZnvEJdzim34WmQ+q8=; b=e7GeVzG7VGLVPEf/kPVwzQinJKN1aVyFju7u/U+ARF7qFXWRUsLFfUggIfXwPdWn7r M08mtvoNJTGV+kga6BPg7kGwOGfwo5ykZN4UC5G95E5zIAN/KKez19EY1LJ43+tN6o+c 66cdYbAZiiD8VbiQ4ye0CdXE18aPCZTdZ10DOo0rAEi15E94E89FLErIA5v0BhMjrYZE Tv1xODvrGXDBe2cncgl7q34OMAF599De7MFKFsXRDrX3/lWBlKcYX0BwgkFDfH73Dmos nGnk4GCIC1AT2M/nOD2fOYp9Dts9K3+RI+yNegEIvB4GdW1Tgj3ceG8wF3fli5712Tm8 8ijw== X-Gm-Message-State: APjAAAWIIj7ZWE9hCfgkxCxTyEJiCl4krWu/nGC0CzIHYs8Fu/N5VECW Xy8V+BQgglZKjn4lO+C/rMa+p/4tzXc= X-Google-Smtp-Source: APXvYqyyjv4fLjo+oyGYCsVCI5nasI3GONHx4lFzfytCasfenGK3gbTutnpws7AafXrv+jwtMbgFYw== X-Received: by 2002:a65:5c82:: with SMTP id a2mr50043330pgt.378.1558002537858; Thu, 16 May 2019 03:28:57 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:b852:bd51:9305:4261]) by smtp.gmail.com with ESMTPSA id h123sm9338048pfe.80.2019.05.16.03.28.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 May 2019 03:28:57 -0700 (PDT) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 3/3] fdt: add support for rng-seed Date: Thu, 16 May 2019 18:28:17 +0800 Message-Id: <20190516102817.188519-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190516102817.188519-1-hsinyi@chromium.org> References: <20190516102817.188519-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190516_032859_323458_2BD4D699 X-CRM114-Status: GOOD ( 17.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Yu Zhao , Kees Cook , Ard Biesheuvel , Catalin Marinas , Stephen Boyd , Chintan Pandya , Will Deacon , linux-kernel@vger.kernel.org, Mike Rapoport , Jun Yao , Miles Chen , Rob Herring , James Morse , Hsin-Yi Wang , Andrew Murray , Andrew Morton , Laura Abbott , Frank Rowand , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Introducing a chosen node, rng-seed, which is an entropy that can be passed to kernel called very early to increase initial device randomness. Bootloader should provide this entropy and the value is read from /chosen/rng-seed in DT. Signed-off-by: Hsin-Yi Wang --- change v2->v3: 1. use arch hook for fdt pgprot change 2. handle CONFIG_KEXEC --- Documentation/devicetree/bindings/chosen.txt | 14 +++++ drivers/of/fdt.c | 55 ++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/Documentation/devicetree/bindings/chosen.txt b/Documentation/devicetree/bindings/chosen.txt index 45e79172a646..fef5c82672dc 100644 --- a/Documentation/devicetree/bindings/chosen.txt +++ b/Documentation/devicetree/bindings/chosen.txt @@ -28,6 +28,20 @@ mode) when EFI_RNG_PROTOCOL is supported, it will be overwritten by the Linux EFI stub (which will populate the property itself, using EFI_RNG_PROTOCOL). +rng-seed +----------- + +This property served as an entropy to add device randomness. It is parsed +as a byte array, e.g. + +/ { + chosen { + rng-seed = <0x31 0x95 0x1b 0x3c 0xc9 0xfa 0xb3 ...>; + }; +}; + +This random value should be provided by bootloader. + stdout-path ----------- diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index e84971d1e9ea..e9862657268d 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -24,6 +25,8 @@ #include #include #include +#include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -1087,11 +1090,14 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname, return 0; } +int rng_seed_size; + int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, int depth, void *data) { int l; const char *p; + const void *rng_seed; pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); @@ -1126,6 +1132,16 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, pr_debug("Command line is: %s\n", (char*)data); + rng_seed = of_get_flat_dt_prop(node, "rng-seed", &rng_seed_size); + if (rng_seed && rng_seed_size > 0) { + add_device_randomness(rng_seed, rng_seed_size); + + /* try to clear seed so it won't be found. */ + update_fdt_pgprot(PAGE_KERNEL); + fdt_delprop(initial_boot_params, node, "rng-seed"); + update_fdt_pgprot(PAGE_KERNEL_RO); + } + /* break now */ return 1; } @@ -1327,4 +1343,43 @@ static int __init of_fdt_raw_init(void) late_initcall(of_fdt_raw_init); #endif +#ifdef CONFIG_KEXEC +static int update_fdt_random_seed(struct notifier_block *nb, + unsigned long code, void *unused) +{ + int node; + void *rng_seed; + + if (!kexec_in_progress || !rng_seed_size) + return NOTIFY_DONE; + + node = fdt_path_offset(initial_boot_params, "/chosen"); + if (node < 0) + node = fdt_path_offset(initial_boot_params, "/chosen@0"); + if (node < 0) + return NOTIFY_DONE; + + rng_seed = kmalloc(rng_seed_size, GFP_ATOMIC); + get_random_bytes(rng_seed, rng_seed_size); + + update_fdt_pgprot(PAGE_KERNEL); + fdt_setprop(initial_boot_params, node, "rng-seed", rng_seed, + rng_seed_size); + + kfree(rng_seed); + + return NOTIFY_DONE; +} + +static struct notifier_block fdt_random_seed_nb = { + .notifier_call = update_fdt_random_seed, +}; + +static int register_update_fdt_random_seed(void) +{ + return register_reboot_notifier(&fdt_random_seed_nb); +} +late_initcall(register_update_fdt_random_seed); +#endif + #endif /* CONFIG_OF_EARLY_FLATTREE */