From patchwork Fri May 17 16:47:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10948255 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 0F01D1390 for ; Fri, 17 May 2019 16:48:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFE792838B for ; Fri, 17 May 2019 16:48:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E15A32835B; Fri, 17 May 2019 16:48:11 +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=unavailable 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 8017F2835B for ; Fri, 17 May 2019 16:48: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=olXecpYJ/EPlXB+Ri0BX7GeyugvGOs6b9faje5GouP8=; b=LoMzt/vWOKGPhL Y8u87bTKKnk0i+AtqLkfZSPKWFLh7yYChnEiVvvwBR2y7K1igaxGSc3KIT6Ggyn/Jme5PyLH3xSeS k7LYJdF0DwOY8BheBzWdsWXSbQhOMCcl80A9d3ym6rPdHFIBqgAC7Q7AzRFTmR1vTTQkumSZ6pLlb OKH+KCCeHtQ/b7FsvaewlxC9HBzEdvFOK5V1tRhreeFoDvwHf64KC01oY9Abt0pbWQcr+WnLS1zLl 2j7WoGg1SpueRrJwbz5zFOnvl320IS58RKBKA4fSNEIhBQ4kY7d+gGJd4R1HZlqDhn1F8+vHypgeX OLGjNAAUerauNz/sdJaw==; 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 1hRg1c-0007ep-7M; Fri, 17 May 2019 16:48:04 +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 1hRg1Q-0007SG-Fp for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2019 16:47:53 +0000 Received: by mail-pf1-x441.google.com with SMTP id v80so3956736pfa.3 for ; Fri, 17 May 2019 09:47: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=Dt/r9hghbvHRpM950rNfaqeDb6HHc3YxElzsbgb3628=; b=ELBsaFN8oBFo7zIK4AKnzx6dpfch/T8r5+SNxrpXpOQYdh4vleaWEpO9Y1yd1e7YpH v5v4iv3CmptHKW7CSR/OFrjxedmV7UdZYU0CuLLH0aHxSUHeot3mJ5kN7M5W10+7ssYv QR2zQxpcFQzfE91l4uLKK9N05oRfi2ZTVG+yw= 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=Dt/r9hghbvHRpM950rNfaqeDb6HHc3YxElzsbgb3628=; b=kbVYFO5Q7ulcDp4PynX/Rn4rJGs6EYHAiWVfPvTWr4D9RU66PHJodC/d8Zw+wrhVvf 7tt/594vBkGw463cVbA5u8s9Zg5TDBocXWxXfSbHcZBAfKZAeYdgyV95gRtaz5zKkD7D YOwElp2zyVF3AaiwcR3tU8QiGwdIos77z4pnIVuDSNr3Fyu3MLVt8gZEOEbDfb0US8n9 dDi82G+WmnmTsGZVRTWWne4P6fObwC7iT+fnqREo4f+pj1tQa4blR+x4+l+9C+tLW68s r0g51tOpZ1pcwKztoPwi/y05gWVjlxartMNfb0UUKZ5dmmnxxfCO0d5Ygv5Mqkc+uv+5 la2w== X-Gm-Message-State: APjAAAUeECJsfKrBotbvD2F09h8tfU4+GXtLI3MswwXVy8RTx/gIYPbk ekxFwabJVp8IJRg7eCugg3Bpyw== X-Google-Smtp-Source: APXvYqxUOQ607cIWfGf9dbtUWQEfdBIaBbRL7/bhUOO2Fqka7KMkLhJ2lePdV2L8GZHvT7d0TjZSDg== X-Received: by 2002:a63:4147:: with SMTP id o68mr55522959pga.76.1558111671899; Fri, 17 May 2019 09:47:51 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id l141sm12229810pfd.24.2019.05.17.09.47.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:47:51 -0700 (PDT) From: Stephen Boyd To: linux-kernel@vger.kernel.org Subject: [RFC/PATCH 1/5] reserved_mem: Add a devm_memremap_reserved_mem() API Date: Fri, 17 May 2019 09:47:42 -0700 Message-Id: <20190517164746.110786-2-swboyd@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190517164746.110786-1-swboyd@chromium.org> References: <20190517164746.110786-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190517_094752_522934_0012C8DE X-CRM114-Status: GOOD ( 15.12 ) 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: devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Will Deacon , Andy Gross , Evan Green , Bjorn Andersson , Rob Herring , Catalin Marinas , Dan Williams , linux-arm-kernel@lists.infradead.org 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 We have a few drivers that need to get a reserved memory region, request the region, and map the reserved memory with memremap(). Add an API to do this all in one function call. Cc: Evan Green Cc: Rob Herring Cc: Bjorn Andersson Cc: Andy Gross Cc: Will Deacon Cc: Catalin Marinas Cc: Dan Williams Signed-off-by: Stephen Boyd Reviewed-by: Rob Herring --- drivers/of/of_reserved_mem.c | 45 +++++++++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 6 +++++ 2 files changed, 51 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 6a36bc0b3d64..39ab2bfd40d7 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -12,6 +12,7 @@ #define pr_fmt(fmt) "OF: reserved mem: " fmt #include +#include #include #include #include @@ -395,3 +396,47 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) return NULL; } EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); + +/** + * devm_memremap_reserved_mem() - acquire reserved_mem from a device node, + * request and memremap it + * @dev: device with node pointer of the desired reserved-memory region + * @flags: flags to pass to memremap() + * + * This function allows drivers to acquire a reference to the reserved_mem + * struct based on the device's device_node handle, request it and then + * memremap() it. + * + * Returns: A remapped reserved memory region, or an error pointer on failure. + */ +void *devm_memremap_reserved_mem(struct device *dev, unsigned long flags) +{ + void *dest_ptr; + struct reserved_mem *rmem; + struct resource *res; + const char *name; + + rmem = of_reserved_mem_lookup(dev->of_node); + if (!rmem) { + dev_err(dev, "failed to acquire memory region\n"); + return ERR_PTR(-ENODEV); + } + + name = rmem->name ? : dev_name(dev); + + res = devm_request_mem_region(dev, rmem->base, rmem->size, name); + if (!res) { + dev_err(dev, "can't request region for reserved memory\n"); + return ERR_PTR(-EBUSY); + } + + dest_ptr = devm_memremap(dev, rmem->base, rmem->size, flags); + if (!dest_ptr) { + dev_err(dev, "memremap failed for reserved memory\n"); + devm_release_mem_region(dev, rmem->base, rmem->size); + dest_ptr = ERR_PTR(-ENOMEM); + } + + return dest_ptr; +} +EXPORT_SYMBOL_GPL(devm_memremap_reserved_mem); diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index 60f541912ccf..a36be60ef67c 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -39,6 +39,7 @@ void fdt_init_reserved_mem(void); void fdt_reserved_mem_save_node(unsigned long node, const char *uname, phys_addr_t base, phys_addr_t size); struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); +void *devm_memremap_reserved_mem(struct device *dev, unsigned long flags); #else static inline int of_reserved_mem_device_init_by_idx(struct device *dev, struct device_node *np, int idx) @@ -54,6 +55,11 @@ static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np { return NULL; } +static inline void *devm_memremap_reserved_mem(struct device *dev, + unsigned long flags) +{ + return NULL; +} #endif /** From patchwork Fri May 17 16:47:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10948259 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 71931912 for ; Fri, 17 May 2019 16:48:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60371283A2 for ; Fri, 17 May 2019 16:48:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53C78283A8; Fri, 17 May 2019 16:48:16 +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 EB8752835B for ; Fri, 17 May 2019 16:48:15 +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=GLPa5tpyBSofvJ7WjOhtnE1Rz79FQekhOc5t5hEkPlk=; b=pDD01uXBIAYKic PPJA14GedgFVlF9SWckFUx+oibevCMWRJB2lFMH6imAKAeDvRNpL3NAhNDFxBc7B+y462HOYoS1Ak sTPtl9PqOKiZDA2Zao+VRxUNxF19uJ2i9maohifbMJRJ4dxOjdcDpO+9eCNeJlvI5buJKtJ27G8Qw yYAJ4ZHx6K61sFFNWobNDAPK+WCQ4sol/CzSE9yqa6hoWp5Bty6hPe4oJfKyl9WNqlq9a4D31CGNw DqnYUPZh1f9j3k/G3t7E7ffF5UiPhya8u8AsEmOSOTwd3QH7aR7XDZntUCh2299mhLtU7KuNEIB6a KQv88Itvslk9zl0KA9ZQ==; 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 1hRg1m-0007sQ-KT; Fri, 17 May 2019 16:48:14 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRg1R-0007SV-BL for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2019 16:47:54 +0000 Received: by mail-pl1-x641.google.com with SMTP id a5so3577519pls.12 for ; Fri, 17 May 2019 09:47:53 -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=ZrfU3jaOv3gonSUyJKcZeL36dqfb9Wzrb+12t37zMDc=; b=hCa6JuKSMM9Bs3WxT0qkjiSBEXmEf/LJdLX0/dKlb6nuQwSG6kwb+JGDS+mg5gfu9X Qrs4zMwjPISN3L2TwsmafobEXz1L5rOYHtS6cdmePanxz8zkBJIDmu0PpB2QMuj3sFCm CTPLfkxGffpChmq0cY2gI2ZmTf4OFrXugT+0A= 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=ZrfU3jaOv3gonSUyJKcZeL36dqfb9Wzrb+12t37zMDc=; b=c/uYdcAlXpcPluXrdGkTMqS5reViccSVA9Gj9wCoA9XmlFupO1xrOYhsEhz59GsZuM j1Nx7/7HtK6TE/v1aJ1aYV4tFuBalu7Y7jwAcBdkbOif0Vn6hMDqKafFUB9dcHl+w5Tn WaOfPMFBcIj0EjGTBgbO2aXVTF5S35B2HSXNoDd0dNWRa4S6KOHY2mbfqFYIdPwPuCnu f2tX3G08TSA4SyzvXWvJZOCq8bkz11oVHWX+l6VgE2lq+bNPvEXXSVrqibafGaX4IvHz SnJHHFEkWVqgj1QmUANrM65UE0NNL+NZjnsrt8zs/Bzd6xPLKACB3DuyQkN3VDiZsUHx z8Og== X-Gm-Message-State: APjAAAWx2OI1kd9tosUa7g5F61/11cfHw6R0+yBvD6ZEJonoWo/IkZ7C cJn/Qz8l5BWbrNGqZTw8gkRhlsMMhBV7xg== X-Google-Smtp-Source: APXvYqwzfl7bTpdEQKPRd5yF2qk0elfKWYm1umwxZQ/tTfqWpMHqi0G8Q3pmuAWOtsRl2T6ICJd6KA== X-Received: by 2002:a17:902:e108:: with SMTP id cc8mr46847446plb.145.1558111672832; Fri, 17 May 2019 09:47:52 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id l141sm12229810pfd.24.2019.05.17.09.47.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:47:52 -0700 (PDT) From: Stephen Boyd To: linux-kernel@vger.kernel.org Subject: [RFC/PATCH 2/5] soc: qcom: cmd-db: Migrate to devm_memremap_reserved_mem() Date: Fri, 17 May 2019 09:47:43 -0700 Message-Id: <20190517164746.110786-3-swboyd@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190517164746.110786-1-swboyd@chromium.org> References: <20190517164746.110786-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190517_094753_386971_DE7FDEE3 X-CRM114-Status: GOOD ( 13.72 ) 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: devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Will Deacon , Andy Gross , Evan Green , Bjorn Andersson , Rob Herring , Catalin Marinas , Dan Williams , linux-arm-kernel@lists.infradead.org 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 This gets rid of some duplicate code, and also makes the reserved memory region show up as 'cmd-db' memory in /proc/iomem. Cc: Evan Green Cc: Rob Herring Cc: Bjorn Andersson Cc: Andy Gross Cc: Will Deacon Cc: Catalin Marinas Cc: Dan Williams Signed-off-by: Stephen Boyd --- drivers/soc/qcom/cmd-db.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c index f6c3d17b05c7..10a34d26b753 100644 --- a/drivers/soc/qcom/cmd-db.c +++ b/drivers/soc/qcom/cmd-db.c @@ -238,18 +238,11 @@ EXPORT_SYMBOL(cmd_db_read_slave_id); static int cmd_db_dev_probe(struct platform_device *pdev) { - struct reserved_mem *rmem; int ret = 0; - rmem = of_reserved_mem_lookup(pdev->dev.of_node); - if (!rmem) { - dev_err(&pdev->dev, "failed to acquire memory region\n"); - return -EINVAL; - } - - cmd_db_header = memremap(rmem->base, rmem->size, MEMREMAP_WB); - if (!cmd_db_header) { - ret = -ENOMEM; + cmd_db_header = devm_memremap_reserved_mem(&pdev->dev, MEMREMAP_WB); + if (IS_ERR(cmd_db_header)) { + ret = PTR_ERR(cmd_db_header); cmd_db_header = NULL; return ret; } From patchwork Fri May 17 16:47:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10948263 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 4DB8D912 for ; Fri, 17 May 2019 16:48:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A5F52835B for ; Fri, 17 May 2019 16:48:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DD4728397; Fri, 17 May 2019 16:48:30 +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=unavailable 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 B24FF2835B for ; Fri, 17 May 2019 16:48:29 +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=mOkB2VYUpklKf7L0Zlmju6L5/S4YpDT2tOec/cX2f00=; b=YPuxUih7gWmfEl zlitZN1Yxl4wj5PT3aSSHS4Lsul3nd1yZejoYnWLHCdcToFjy1L1fNwoBfVjE5nugwavZeKVBOrFB jSOEuDVP/E9Lesq7B0k5I7Pxy/1I0L7AEsuTuQuuySL9Am8+zDWLaUZO0/n61cyH7YW91AsfUQ1/B qWKH4xVwygScI3ch+43n8gi/gGNOYOSd510l7BKo2YXHBXrBM2SYwc3DFH5IRWYf9LPINUQXjN5no XCPlh/myrz+smsw/0MswCh7eybh9MkrV1dwaOt0ijdiT33JoF9uNRSK9RVbu7S84Usv7iSXwgU70I hvNx8sJFDgQFJ0Y9tFtw==; 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 1hRg1v-00085i-F4; Fri, 17 May 2019 16:48:23 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRg1S-0007Sr-9G for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2019 16:47:55 +0000 Received: by mail-pl1-x642.google.com with SMTP id r18so3581646pls.13 for ; Fri, 17 May 2019 09:47:54 -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=CqKPKWAOqqK2fAPeJ19AHkkbMpccuE5V5twNlxY2yj4=; b=l5axbd7GCjC8UzCQX6le433fYI5Gy+AP17dysVHzpJd5K1V3v/AHW4gWkJNCz7RvkX U/Da5n4quZkQBum7RcbcB/GoUQGFlxfPOuZ2L8sPSnntSKwbhQY1PEaQHXxJ91PjHzMn phj4VIypQewbe385bAXnxglk7G8q2eho9KcGk= 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=CqKPKWAOqqK2fAPeJ19AHkkbMpccuE5V5twNlxY2yj4=; b=KfrLntm6nHXKcvy+zNsTGr4DFHNcMenKhX8BJTTnMuQZSDqVzT4OYToo6zCX46jEx0 hFFPQmwbP+DhlRXGOZio8THXDl3CvUwF9seQXRID4jpMgZU982FqYYpxO3/4lUavNcFK yycrOxCZSIRv7MSljuvLYA5mrl1Sks5zD9FaJInGXawdwT6nxQ/m0cKWfh5ea5T8/mcM 0D5dT8mJjdFMZuRQECqM9UXuwg8tqpNWhZ/ONKminFDXGVbX/x6PzqTRkdIonIq9uYI5 hxCzG8uNSEjrNbarO9FoC2aHqpdR/LJ8AcJQ78aeIiTtNIho5DyOkSc3/xieQrfog/Q6 CXRw== X-Gm-Message-State: APjAAAXl8vGzMiOFDEo90IQjiZw5HL0uYas6v7vSeR/rY3u9mxWdvgTb mvmAhTM0EzYpijL3guQ+/H53pg== X-Google-Smtp-Source: APXvYqyAp8uRsjVVx2sdnL7aIY5IBJRUMYDjonUYiJUCfdadaA7UoNqRxgke+HnZZ6Yy3quetwwBow== X-Received: by 2002:a17:902:ac98:: with SMTP id h24mr1729914plr.265.1558111673755; Fri, 17 May 2019 09:47:53 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id l141sm12229810pfd.24.2019.05.17.09.47.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:47:53 -0700 (PDT) From: Stephen Boyd To: linux-kernel@vger.kernel.org Subject: [RFC/PATCH 3/5] memremap: Add support for read-only memory mappings Date: Fri, 17 May 2019 09:47:44 -0700 Message-Id: <20190517164746.110786-4-swboyd@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190517164746.110786-1-swboyd@chromium.org> References: <20190517164746.110786-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190517_094754_320603_3B55FDAF X-CRM114-Status: GOOD ( 15.84 ) 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: devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Will Deacon , Andy Gross , Evan Green , Bjorn Andersson , Rob Herring , Catalin Marinas , Dan Williams , linux-arm-kernel@lists.infradead.org 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 Sometimes we have memories that are supposed to be read-only, but when we map these regions the best we can do is map them as write-back with MEMREMAP_WB. Introduce a read-only memory mapping (MEMREMAP_RO) that allows us to map reserved memory regions as read-only. This way, we're less likely to see these special memory regions become corrupted by stray writes to them. Cc: Evan Green Cc: Rob Herring Cc: Bjorn Andersson Cc: Andy Gross Cc: Will Deacon Cc: Catalin Marinas Cc: Dan Williams Signed-off-by: Stephen Boyd --- include/linux/io.h | 1 + kernel/iomem.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/linux/io.h b/include/linux/io.h index 32e30e8fb9db..16c7f4498869 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -159,6 +159,7 @@ enum { MEMREMAP_WC = 1 << 2, MEMREMAP_ENC = 1 << 3, MEMREMAP_DEC = 1 << 4, + MEMREMAP_RO = 1 << 5, }; void *memremap(resource_size_t offset, size_t size, unsigned long flags); diff --git a/kernel/iomem.c b/kernel/iomem.c index f7525e14ebc6..8d3cf74a32cb 100644 --- a/kernel/iomem.c +++ b/kernel/iomem.c @@ -19,6 +19,13 @@ static void *arch_memremap_wb(resource_size_t offset, unsigned long size) } #endif +#ifndef arch_memremap_ro +static void *arch_memremap_ro(resource_size_t offset, unsigned long size) +{ + return NULL; +} +#endif + #ifndef arch_memremap_can_ram_remap static bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size, unsigned long flags) @@ -84,7 +91,10 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags) } /* Try all mapping types requested until one returns non-NULL */ - if (flags & MEMREMAP_WB) { + if ((flags & MEMREMAP_RO) && is_ram != REGION_INTERSECTS) + addr = arch_memremap_ro(offset, size); + + if (!addr && (flags & MEMREMAP_WB)) { /* * MEMREMAP_WB is special in that it can be satisifed * from the direct map. Some archs depend on the @@ -103,7 +113,8 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags) * address mapping. Enforce that this mapping is not aliasing * System RAM. */ - if (!addr && is_ram == REGION_INTERSECTS && flags != MEMREMAP_WB) { + if (!addr && is_ram == REGION_INTERSECTS && + (flags != MEMREMAP_WB || flags != MEMREMAP_RO)) { WARN_ONCE(1, "memremap attempted on ram %pa size: %#lx\n", &offset, (unsigned long) size); return NULL; From patchwork Fri May 17 16:47:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10948265 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 5C2E2912 for ; Fri, 17 May 2019 16:48:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49B392835B for ; Fri, 17 May 2019 16:48:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D946283A2; Fri, 17 May 2019 16:48:42 +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 AFF082835B for ; Fri, 17 May 2019 16:48:41 +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=qbkLBVEZCuSB7BcOV+WwiJb9IMOlV4QTbJ8+j5H1EFA=; b=JZsUiM6F9fSDUy htHvLmpUCbcbq1v1taTiwbMwLuUvAPiv57JOp3X+k1N3yU2CETdioteaReidjl5HEW917BTZC9YK/ yMQxHVnJ2MbvxG7lKkAdI2uM4XvtWOvIpk+gc9IOoaWPE9CY8TgOa43lgJGVZYFtlZNdhcAeGYsli Pl5Bi52y6icbHwEdgPcZL4ps6OrN247FhI/vM80n8ThwybiLRpEBY042DWIY1J0BKk6tUt0XB8vcp 9cFDYzCxLvPEa6AHzJLT3ZLbCXPgBhMa5wFuFbyCLEzln+KluegE7aTxx9ixoaPLaMzh0GzWtu/wj wFoMkvOpKuRxcwQZSjEQ==; 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 1hRg27-0008KL-Kw; Fri, 17 May 2019 16:48:35 +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 1hRg1S-0007TH-Vd for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2019 16:47:58 +0000 Received: by mail-pf1-x444.google.com with SMTP id g3so3954382pfi.4 for ; Fri, 17 May 2019 09:47:54 -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=hE0fe9lMVv6/FQxLkF3fQ4UQY6bw1uWnd2q8EpUNjIc=; b=ZhDwx/7uQqUnTIHD1PA1Upu1Y8Z3YXS3B9HztVGpVhQ1tAXH449NhmdQCurju4ZJB9 vNhIXcRedwThXY2BekwHNiWsmcH7xI5RXQTxVxFuMqKhuiq90bGAcOc8hj9Vd5FEss09 u6kj7HIYJx12jSex16z82pa6RCUW1/cmEbwHk= 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=hE0fe9lMVv6/FQxLkF3fQ4UQY6bw1uWnd2q8EpUNjIc=; b=J/Rs7RezeMueBXpddu6yhi+MnCPlw4xpagZfYJoAD17oX65JUl0fs22Tcb0wSp8U6I SlOvIGrsR37N0jZVXcFBgJ+9mfWiyNlnJ6JrXz9SID57Y0nlS9dyWtB+IYwduGGGGMyn RpZnsp2+9KgRqEJhVY0FwKkbH0uOJeq8ao5NwwqearuKtYCZIiJYiM7JZR9xq6EY7sML Cg5j8TUzXEGYRHqvadg+uQw92xzkjRIKK7tzCPw05r1o5y/zm9YPPFshiOaxb7kW4MNr DByj5wZLza2ciq6pLn1PPg3z4AZZYomeWxWmzuwtgyaaTyOr0sFL3L1pu4mmpEPHuTVt 3++w== X-Gm-Message-State: APjAAAWrZGrWeSvGTHC8U/6cIP8W6FASrthu/+Cl12cTVTwBFHPwENZz l058uCXyEs6waJb6utDw64s2uw== X-Google-Smtp-Source: APXvYqzuCXeovIOaR4RbpVXx1csND1I5sP1Zmc0ZU68p58V4I5232ilFAA9A/gPdohyIIkl9VXHhPQ== X-Received: by 2002:a63:785:: with SMTP id 127mr54984321pgh.230.1558111674612; Fri, 17 May 2019 09:47:54 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id l141sm12229810pfd.24.2019.05.17.09.47.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:47:54 -0700 (PDT) From: Stephen Boyd To: linux-kernel@vger.kernel.org Subject: [RFC/PATCH 4/5] arm64: Add support for arch_memremap_ro() Date: Fri, 17 May 2019 09:47:45 -0700 Message-Id: <20190517164746.110786-5-swboyd@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190517164746.110786-1-swboyd@chromium.org> References: <20190517164746.110786-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190517_094755_195541_8F2C4E1D X-CRM114-Status: GOOD ( 11.82 ) 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: devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Will Deacon , Andy Gross , Evan Green , Bjorn Andersson , Rob Herring , Catalin Marinas , Dan Williams , linux-arm-kernel@lists.infradead.org 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 Pass in PAGE_KERNEL_RO to the underlying IO mapping mechanism to get a read-only mapping for the MEMREMAP_RO type of memory mappings that memremap() supports. Cc: Evan Green Cc: Rob Herring Cc: Bjorn Andersson Cc: Andy Gross Cc: Will Deacon Cc: Catalin Marinas Cc: Dan Williams Signed-off-by: Stephen Boyd Acked-by: Catalin Marinas --- arch/arm64/include/asm/io.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index 8bb7210ac286..245bd371e8dc 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -185,6 +185,7 @@ extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size); #define ioremap_nocache(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE)) #define ioremap_wc(addr, size) __ioremap((addr), (size), __pgprot(PROT_NORMAL_NC)) #define ioremap_wt(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE)) +#define arch_memremap_ro(addr, size) __ioremap((addr), (size), PAGE_KERNEL_RO) #define iounmap __iounmap /* From patchwork Fri May 17 16:47:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10948267 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 9BCE9912 for ; Fri, 17 May 2019 16:48:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89F3E2835B for ; Fri, 17 May 2019 16:48:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E3CD28397; Fri, 17 May 2019 16:48:51 +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 2B55D2835B for ; Fri, 17 May 2019 16:48:51 +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=cKV1/g2WAA/amDiGjmjdvtagrmvschf2h9CraraLzNc=; b=BCasYiKkCEJRwD YdGJDTXP3WHBa1pKS17Vbq2nYqKm6V4bq6iBL8WjYfEyHwUZUdetSoXcWwZ8+lEqBS2RY9CMFkKPC IvmDbtiQAl9ujNsYyP6i0yxAX2+o/MhDJy0A9O+OlP+nOtuFMUOUkCFUBz0dttJeXOHlXpF0CDz/+ Ja99Wnmf7k7++v9v7Dj7gY4HKt1zk+I50pN+SHU/U63GGBSn4o236iNCJY4+FoG1heeWYYwWL31Oc 9UXOD8RjTLHc/bofmxmyZQPP2M5iiXYMfzpMVNm/h3UoHA9vebkk+DcunMifBRo0kgRnSZ2tHZnGc 33oiQo11HtNePdclDtbA==; 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 1hRg2G-000061-85; Fri, 17 May 2019 16:48:44 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hRg1T-0007UG-ST for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2019 16:47:58 +0000 Received: by mail-pl1-x642.google.com with SMTP id g5so3608307plt.2 for ; Fri, 17 May 2019 09:47:55 -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=O42F5A4GX0eA84yy8Ef+AkKPQRwJmwFWVhtyExm+PVY=; b=PYP/b3+x4BUW2tXl5EeWPVhQ2Ydr9f0XlD8JFJZdeKuWGUm9x2gBEwCIanOv3mBLby T3lJRIqhz+aMnbrOABRtKWxma2+WZvjeN4x+PFt3loQXcwqG8h15GMZTzENSWae+cGEi HfbFUHK/8IaOWGApHdEcikH6nKx9xsnyyafPQ= 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=O42F5A4GX0eA84yy8Ef+AkKPQRwJmwFWVhtyExm+PVY=; b=Q9Asx1TDQHpdCnqN6cpMhUoKcyJ12oy7Ic0B49KntDk45hMdoq2O3gnudDv7v4k430 NtbuKSyVJZuxdVCOqH8WARFtWhHhRcrrGk4IUUtwBtHmBYQfMXMePEuHqMiCaFKN7W0W lAjwkOik+OPO38lk2HPFN+fGjUD2Ih7TXVy+1EOD9PrZh4pyAYtHXTbMNJDa3PKE6mZ5 fgwTRn4HC0rLjXOD4arTSzzUmIRlVi6qWufOXeek2M95RvC8FdwIs84Vo0ArpGRKr8gt 9oMImrSlfEnMzU04OoimyYlqAVKwjqaJ6iAQeaI3lg215JmbIog6OorTYmq1EFQSePBD hjAQ== X-Gm-Message-State: APjAAAXx9GfAH/NunPiBdeYsJKJCc+65YUK5i17TC16NdExG8avkor3t uzrtpjpbueXn9tywC6tx9fZ/ig== X-Google-Smtp-Source: APXvYqz5grEEF0O5CgARwN/Kl3T5APmZtPmXKSBTqLDuepRs1NbjLFpphhsqHJa3rK39CAOOKrQTJA== X-Received: by 2002:a17:902:968b:: with SMTP id n11mr57741397plp.118.1558111675502; Fri, 17 May 2019 09:47:55 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id l141sm12229810pfd.24.2019.05.17.09.47.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 09:47:55 -0700 (PDT) From: Stephen Boyd To: linux-kernel@vger.kernel.org Subject: [RFC/PATCH 5/5] soc: qcom: cmd-db: Map with read-only mappings Date: Fri, 17 May 2019 09:47:46 -0700 Message-Id: <20190517164746.110786-6-swboyd@chromium.org> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog In-Reply-To: <20190517164746.110786-1-swboyd@chromium.org> References: <20190517164746.110786-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190517_094756_128841_7C59FF84 X-CRM114-Status: GOOD ( 14.98 ) 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: devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Will Deacon , Andy Gross , Evan Green , Bjorn Andersson , Rob Herring , Catalin Marinas , Dan Williams , linux-arm-kernel@lists.infradead.org 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 The command DB is read-only already to the kernel because everything is const marked once we map it. Let's go one step further and try to map the memory as read-only in the page tables. This should make it harder for random code to corrupt the database and change the contents. Cc: Evan Green Cc: Rob Herring Cc: Bjorn Andersson Cc: Andy Gross Cc: Will Deacon Cc: Catalin Marinas Cc: Dan Williams Signed-off-by: Stephen Boyd --- drivers/soc/qcom/cmd-db.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c index 10a34d26b753..6365e8260282 100644 --- a/drivers/soc/qcom/cmd-db.c +++ b/drivers/soc/qcom/cmd-db.c @@ -240,7 +240,8 @@ static int cmd_db_dev_probe(struct platform_device *pdev) { int ret = 0; - cmd_db_header = devm_memremap_reserved_mem(&pdev->dev, MEMREMAP_WB); + cmd_db_header = devm_memremap_reserved_mem(&pdev->dev, + MEMREMAP_RO | MEMREMAP_WB); if (IS_ERR(cmd_db_header)) { ret = PTR_ERR(cmd_db_header); cmd_db_header = NULL;