From patchwork Tue Sep 10 16:08:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11139847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38A8216B1 for ; Tue, 10 Sep 2019 16:09:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1660C206A1 for ; Tue, 10 Sep 2019 16:09:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="THqdqDeC"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WgGiFGhC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1660C206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=jBEODQieZiLAw1tb6F7NuLGkYt6UEdO83HwihMPfHBc=; b=THqdqDeCg1EQsx i82oXJj20WxF/vpkU+s9SrpRiyNmjxNUc3SwXclIz4gZC6ToNtkh/h1s9Hf0O0KwnENnZlsZDlIoK b/QtRCVSrZrv0AC86hKHs2YpCtD9tRM6LH955dnoprNcC2rOwpxceci/Ovb/zlKoazblu8O0+01N3 M+c+r/KY8zOW+UA/S+aexp8KPxmUW5ksnsMFIqq/SMo3CZJE9hLal8dzSO1dVpn+GLCNRjT180rao d2jrRosk9+fad1UAg5PgDNjpaGcFH6dt3XG0alNCDmalXtQDrHBHGggzTuU70Fq5zYoIFKv6ktvp8 3Ep1TlqrDSx9MRQZyqWg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i7ihj-0004YD-IO; Tue, 10 Sep 2019 16:09:19 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i7ihW-0004Kq-3G for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2019 16:09:07 +0000 Received: by mail-pf1-x441.google.com with SMTP id i1so2952633pfa.6 for ; Tue, 10 Sep 2019 09:09:06 -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=HUiGHkQMIXTru33NEpbepH3aRpqrcccJiliaWHN/NLg=; b=WgGiFGhC0+fEZ7JT0OjNHDyPLtBG3IXaHE9JpZEtRV2XqVoXUnKBH4yKD0ALDyd9ck 2OM4E+GQhSWHovAAda2EVwo5DBAambJGR6Ru/sygZR/+5MmXPszT57QDh4A2TkuPw88h HrfbDrERmKljT3OSSYd7McTkRH1e1rZdAj67s= 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=HUiGHkQMIXTru33NEpbepH3aRpqrcccJiliaWHN/NLg=; b=r5TCKzq+AUntj66Y2FMKVOnQQZTkF4ZE0eWo10KZKzbU66fTYAc+qPPldHdVffSgQo 9HcHkONga/7U8r8hJa/5cu2JyglOlWWos4cJihYMRXxzz2Z7OgspZTbV64o/xOuzex36 RPzdTnA7/xHjgzV2ni05waJ3diSik5adsUY8SMz8B4BiuSQ3NFhB1lHPPJ44t4/rifVI ZXVrFM69+L13aIMmL5Nk6cO7jq/Q315dtFWh7/Cg0cOKy668i+q03tk5+N9q4PZCmNHf nd8vElaf1kPAmFH8WbLynYEZkun9cWcOnr8JxTIwA2KfiDLxJBpPKAF6042btf6wjfwy zIqQ== X-Gm-Message-State: APjAAAUi0mOZZTCcUKKzW2sGaYYNr15CzJaaBqVgTX6+vvjpsUnzFnhh CTFV2CTMBdnsgxSUpmfZAgMNRg== X-Google-Smtp-Source: APXvYqwEeEfNXla76FaGP5TGBYBOatyT898AHWyJZN2OgmIQpcAR1+y4Xp5qzzvgO8bXi6iPgi7SEA== X-Received: by 2002:a63:f04:: with SMTP id e4mr27801248pgl.38.1568131745594; Tue, 10 Sep 2019 09:09:05 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id em21sm106088pjb.31.2019.09.10.09.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 09:09:05 -0700 (PDT) From: Stephen Boyd To: Dan Williams Subject: [PATCH v3 1/5] reserved_mem: Add a devm_memremap_reserved_mem() API Date: Tue, 10 Sep 2019 09:08:59 -0700 Message-Id: <20190910160903.65694-2-swboyd@chromium.org> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190910160903.65694-1-swboyd@chromium.org> References: <20190910160903.65694-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190910_090906_135698_8885B5B1 X-CRM114-Status: GOOD ( 14.82 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:441 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Rob Herring , linux-arm-msm@vger.kernel.org, Will Deacon , linux-kernel@vger.kernel.org, Evan Green , Bjorn Andersson , Rob Herring , Andy Gross , Catalin Marinas , 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 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 Reviewed-by: Bjorn Andersson Reviewed-by: Rob Herring Signed-off-by: Stephen Boyd --- 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 7989703b883c..b3899a2c74c4 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 @@ -410,3 +411,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 Tue Sep 10 16:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11139853 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57DE616B1 for ; Tue, 10 Sep 2019 16:09:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 31DC8208E4 for ; Tue, 10 Sep 2019 16:09:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CB4jijv8"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jB5WWGwX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31DC8208E4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=XLXXvj7n3hXQt+SIwTC2uh6ev9+CHz7+tlatL4dMT7I=; b=CB4jijv8//yq1V A5iZ08jPtBpL2lTDs528yZMBPIbSmVheWGE7wkI9LKRehyPTSQsXcum8LJaxIGpSlomc1Sq7f+gvt yMWWfy1IWZ4mkTj/ukRKTXR2owTANFs8oVTGBstgJHXhP1rbnScRd+03StSPnnEP3WPzEN7/uOZfQ bWltM7oL2zCCdL4pADl2e0fHqjonQKrd+r8aeDFCyu+As/zcx+nI1QgVoSwLhVrPdsn93/xOhP3QB gjNlBA/Vie5pjbMe3f2Cq+xiefojdeLHvO0Xwi/FfarZeM8n7IvM8P8l+bbAljdzidmiYPfaBJNHJ eFWTJIUSxv8badhS1lOw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i7ihy-0004nP-Ah; Tue, 10 Sep 2019 16:09:34 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i7ihY-0004L4-PZ for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2019 16:09:10 +0000 Received: by mail-pf1-x442.google.com with SMTP id y72so11764001pfb.12 for ; Tue, 10 Sep 2019 09:09:06 -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=Xc2tEV/bPIimEWuq/mx6XQl4uW5E/9HmwBDqWANEBLQ=; b=jB5WWGwXXLkjLvAZdoToyHkhH94srGZ60DUbpccXHx2zP3koKdzgSTxjWRTMyUUxk6 qE2Mewj7ZGC868dmVOUcDDOjEiEAq0Da31quy/iR3ruDW7+raxlYAd5XZ2gNAoIxSTyP NwcNvTP1AJVqo7kxOWlm1+JJQoQj/vEd7L2aY= 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=Xc2tEV/bPIimEWuq/mx6XQl4uW5E/9HmwBDqWANEBLQ=; b=dFeSX/dbknL1VDeD/rglx7oo1ZNPP1hn/+GJ4gn5313UIJ2u2CH5/pIToFljIE51KB pFaPLfJjRRS1J38bKRME3Z5jCqnYrbIYftJNsTE9zuo7QG6iMw76S2OJqUqbvwjsSa+0 bWZ4B0OFDepD5Sj9Cv1f0js/jMsGJ7Jn1O2+BZNRgqxehAsBReWW6Q8U0CBz/jXVsAhu HOTMnYFbcq5I3DzgLidZ+VRhYELevkYvZPVS6lf9GDmCsALYEDIq1aGHhPuEA+vIWXid H7F5XktaNiX8GPfp4+osz7AAZYYnMLMnLOhb9zcf3Xoo6Dw/2RPjJQe32D4cTLd9yk8V Yn2A== X-Gm-Message-State: APjAAAXHX/e9bb2FQ3Wefrgc1BaXQr5Q6lFrsxbHQ0V7/VYIsoTQMNqw A0vUzPkCRN5XzJA+JAcEXERHyw== X-Google-Smtp-Source: APXvYqwQde81cPZARFYDS6NyOn+6Q4omsTP/UbXDzMG+88WgYZM8ISB0CE0RNxmhB0RjPIeWde62HA== X-Received: by 2002:a62:cd45:: with SMTP id o66mr37338117pfg.112.1568131746464; Tue, 10 Sep 2019 09:09:06 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id em21sm106088pjb.31.2019.09.10.09.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 09:09:06 -0700 (PDT) From: Stephen Boyd To: Dan Williams Subject: [PATCH v3 2/5] soc: qcom: cmd-db: Migrate to devm_memremap_reserved_mem() Date: Tue, 10 Sep 2019 09:09:00 -0700 Message-Id: <20190910160903.65694-3-swboyd@chromium.org> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190910160903.65694-1-swboyd@chromium.org> References: <20190910160903.65694-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190910_090908_843951_6B91E814 X-CRM114-Status: GOOD ( 13.62 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 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 , linux-kernel@vger.kernel.org, Evan Green , Bjorn Andersson , Rob Herring , Andy Gross , Catalin Marinas , 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 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 Reviewed-by: Bjorn Andersson 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 Tue Sep 10 16:09:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11139855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0F3816B1 for ; Tue, 10 Sep 2019 16:09:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CE521206A1 for ; Tue, 10 Sep 2019 16:09:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="K+6mdPRX"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="foUXLvfX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE521206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=wbJAl9DqQ7IyeITrr3f31uQcKHvhctil5ttLTpjIvIk=; b=K+6mdPRXhuW1uj nKS5cqE4LZ6Gdv15XP0Qp1xbyqjwrcAA/4CaYo02EqshDRgqXTA/Szr2py8vX4jwdFNJBr1vxSWpB 1Dy9+6c6LW5xdFJCEMtcEKDMTVW3oUHLot+8MTgHAzm5XlNzwGJ+OgVmDWODhx+trZgzfrmd5dYPV 68Nm+iGoSh3BF0hRuZEO84GJYUtcN7dLceJ50LCpounoYtn2DkhAnVAtcE8IwIvhwLipnKWZmeUwS gBkvHbKr2RT2mI/GaJkLfstRhphsy7kAfyImkcpoSGgsUgSYejAjEKfqvrI5Ku3OUnbPN4r15rZZl MyubACey3V/4shQ/LAyg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i7iiB-0004z7-2m; Tue, 10 Sep 2019 16:09:47 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i7ihY-0004LF-QB for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2019 16:09:10 +0000 Received: by mail-pf1-x443.google.com with SMTP id y22so11816970pfr.3 for ; Tue, 10 Sep 2019 09:09:07 -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=YIkLTnrkWt/EuuPaM/5KgusucJyV+/pu2XQTD6+l1B4=; b=foUXLvfXEBZ8ItH2km73P/GyOobcyj/2AlkrAl5hS06ssjzVy3VMEdus9dZJ3XfRko n3d1oj1yZXYkG2g88eBnSetaXilib5WWGGyXSHK7SjUDXQXeIo8DFzlrCmNLoyCGk1MI BMHL2SWL8Fvoc+XCOlcilC9vuG29PN8KWwjVs= 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=YIkLTnrkWt/EuuPaM/5KgusucJyV+/pu2XQTD6+l1B4=; b=h8OW9cdl1vvPn+0fu5sccZeoLKOEZ071fixZU3Nu3MKUZEiPueyO45rVqdkEIC+ouT hl26fqv38wajjpBGoiEz7yZmvO/MuUrzijIRTM4x1bmeYLBRB/txSkAto3V3hw/zw9pY R7uT8XdtG+gCsBKikl5vWQhbYG97LE3JE+n3UnFtRXua451I48bjINllcd6r5W/DMmWW BRr5fRNPTXnLXve0asBIethiTbUuodD3J0KdzyH/nSrqExB2O/G0Fp8tjlQTd9AjfbxC efXUrtO3KPv9nVqdCvUn5HpF7Exz6F4IdDInnxtksN4PtYZgg1Jg1b99od+2HmP+fdp+ dkOA== X-Gm-Message-State: APjAAAXKS8Hdda9VKGf1f+sLHwIPPKwcMfydQUWUDvMD2IAOFe44UHLR aTb+Xh5+8Vq1Fn/XbI4OPGc9Yw== X-Google-Smtp-Source: APXvYqxx4DKXHSRmc5pwbVIhiOSXS9FCZbm2hSlKbDrWsuFklc4KYT0VzXEO62KHo4IIpzzRXcJKAg== X-Received: by 2002:aa7:81d1:: with SMTP id c17mr35893243pfn.219.1568131747300; Tue, 10 Sep 2019 09:09:07 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id em21sm106088pjb.31.2019.09.10.09.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 09:09:06 -0700 (PDT) From: Stephen Boyd To: Dan Williams Subject: [PATCH v3 3/5] memremap: Add support for read-only memory mappings Date: Tue, 10 Sep 2019 09:09:01 -0700 Message-Id: <20190910160903.65694-4-swboyd@chromium.org> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190910160903.65694-1-swboyd@chromium.org> References: <20190910160903.65694-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190910_090908_865994_661CAB78 X-CRM114-Status: GOOD ( 17.98 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:443 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 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 , linux-kernel@vger.kernel.org, Evan Green , Bjorn Andersson , Rob Herring , Andy Gross , Catalin Marinas , 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 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 Reviewed-by: Bjorn Andersson Signed-off-by: Stephen Boyd --- include/linux/io.h | 1 + kernel/iomem.c | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/linux/io.h b/include/linux/io.h index accac822336a..15a63efcd153 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -148,6 +148,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 62c92e43aa0d..6d76b7398714 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) @@ -45,7 +52,7 @@ static void *try_ram_remap(resource_size_t offset, size_t size, * @offset: iomem resource start address * @size: size of remap * @flags: any of MEMREMAP_WB, MEMREMAP_WT, MEMREMAP_WC, - * MEMREMAP_ENC, MEMREMAP_DEC + * MEMREMAP_ENC, MEMREMAP_DEC, MEMREMAP_RO * * memremap() is "ioremap" for cases where it is known that the resource * being mapped does not have i/o side effects and the __iomem @@ -53,6 +60,9 @@ static void *try_ram_remap(resource_size_t offset, size_t size, * mapping types will be attempted in the order listed below until one of * them succeeds. * + * MEMREMAP_RO - establish a mapping whereby writes are ignored/rejected. + * Attempts to map System RAM with this mapping type will fail. + * * MEMREMAP_WB - matches the default mapping for System RAM on * the architecture. This is usually a read-allocate write-back cache. * Moreover, if MEMREMAP_WB is specified and the requested remap region is RAM @@ -84,7 +94,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 satisfied * from the direct map. Some archs depend on the @@ -103,7 +116,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 Tue Sep 10 16:09:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11139857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2FACE16B1 for ; Tue, 10 Sep 2019 16:10:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0B8FC21019 for ; Tue, 10 Sep 2019 16:10:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="aFuXBxUy"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="T2zSyHcE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B8FC21019 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=jU1cefWla9xXtalZtz18B0X+o/rSUX7uuFq/lJwHlg0=; b=aFuXBxUy6vd4Xa fqJjjIzAjUHrdUs5VI1ucN93Xf/Z1i39eL58jbM7r1XammSOUpDDh9TlfG7UAC2/lW4jiLrjCKNKV uFPdCGhjgGcZiAMvLsrkYGq04Y16RChsYNlzIUGHpMhW0O5Vq8E0ddPxQv/KPLTYVZAcrXOocgYZb LIvm8hrJu+GKn6T2K3B/XtkWEYmImdOZqCx4/aiua9JM+ShWhNVCDGtAroQrhQPHKDcP8eXiOPARg nplTsKM7ZFgY1A6ffbKTUiEyT3Gyu1BrLVw9rHf8rWYQ6NJbq0pfSfpOWlD2c88JZ1Y8ReZ01cFEC qwgqf079uOAIEaeBvQKQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i7iiO-0005Dq-0a; Tue, 10 Sep 2019 16:10:00 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i7ihY-0004LK-Vy for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2019 16:09:11 +0000 Received: by mail-pg1-x541.google.com with SMTP id d10so9986278pgo.5 for ; Tue, 10 Sep 2019 09:09:08 -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=BXles0cH5YGr7OfqkOJ72KVG5DkMe0UjZVzH2kBE6hs=; b=T2zSyHcEiyCtbS8xoj/ECUACFJexd7ZGxA/Cwu1Ed2uaIIhPjEgfE8/61M2nZVJLBm naR6pG28QpnVsTp2W51i+6ULyNWT6kVyhO8VoOvzKVTHc5F2cwDTufQa4OF3FyYP04dk APV2Ac6LXoj1jxXRVHsGEBPoEuvTGMNcF+7Lc= 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=BXles0cH5YGr7OfqkOJ72KVG5DkMe0UjZVzH2kBE6hs=; b=mVgol5h+sd6BEwff9z8cp44dt26EoE4EVldv5DGoYwDqF0IfysDTEJ/YPCfAej5AvQ KNNLFVlWEDJffNBjvvodD3m7AhoWMgWNwV6g7h0aQzjn8WgrFfXJXkJ7/eROiQQNTbQq DNs/eH88Iy5fDSPBSdCpWz4W9nOfaN/j3lIbQ6OJ7OMVPCukz2qUr+afzzKE09FjVmIf TeqqD1BAJCPbCCCjSB3263UO6Rl27J/sAtwS52NO9M1AaSCW7FqIK7kvZ6Qy7BOeFbhL RkRpT+MelA7kxTnup8slMknScolHwJtZTE6anEUYQFAdApNP1XXLf/WLBRQEvKMncyb6 s5jA== X-Gm-Message-State: APjAAAUZzTX/WLtZ2B9Jf/W4s3ipx8OzPIsDE/IFXH7VJ25+IwzRBsIG +JItUStK9EwR51JLubWKgg1+fAX3zx3g4g== X-Google-Smtp-Source: APXvYqwdWlZubSWHnT9D8yZ1LDDemTMKo+tmMy94vJ9+/SnQHMWaD5lO6RzbXotNH1LnwMd6vahwOA== X-Received: by 2002:a65:4b89:: with SMTP id t9mr28326267pgq.55.1568131748161; Tue, 10 Sep 2019 09:09:08 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id em21sm106088pjb.31.2019.09.10.09.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 09:09:07 -0700 (PDT) From: Stephen Boyd To: Dan Williams Subject: [PATCH v3 4/5] arm64: Add support for arch_memremap_ro() Date: Tue, 10 Sep 2019 09:09:02 -0700 Message-Id: <20190910160903.65694-5-swboyd@chromium.org> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190910160903.65694-1-swboyd@chromium.org> References: <20190910160903.65694-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190910_090909_065247_916878E5 X-CRM114-Status: GOOD ( 11.62 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 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 , linux-kernel@vger.kernel.org, Evan Green , Bjorn Andersson , Rob Herring , Andy Gross , Catalin Marinas , 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 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 Reviewed-by: Bjorn Andersson Acked-by: Catalin Marinas Signed-off-by: Stephen Boyd --- 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 7ed92626949d..c623e75d9152 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -172,6 +172,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 Tue Sep 10 16:09:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 11139859 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C7A314ED for ; Tue, 10 Sep 2019 16:10:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A570206A1 for ; Tue, 10 Sep 2019 16:10:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZimvuVsk"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mdVQsy1c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A570206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=dtg7JHU3Xb/l5we36pyZWoOvc0+yoiaAFW+eaiVuxBU=; b=ZimvuVskAhWPyi OFE7V1MeFD0l0n+dyul179y0uWbJ253gYqV5x695XWLsWINuiJ/Qs2hwRfzvf7tSyhtqZtYVXvH8Y tT+AprYQlbDn/4dhDgMP3aFvc0NsIaZbGoxuqYnryQku8+O3cClNtQmJZ63TtGUY5tg81BCVLBklO XwAnPqJN5bwB8r0JB9FNfSrqJL3F3CjQtLCE7ID6M5Ry7SfWjYodvSRmYNq8auvS+V/sVqUm8bWbH CEhMeR0tX6wLkDjQO8jo0yhA8T0XcFkXJIKnmrQ3ZWoFvaxjTLkLv+hmEUsK7MJyL8fGWiN54u0yT 57vD1GB9b2XC8P3BjiBA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i7iie-0006hJ-Q1; Tue, 10 Sep 2019 16:10:16 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i7ihZ-0004Mk-W7 for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2019 16:09:12 +0000 Received: by mail-pf1-x444.google.com with SMTP id q5so11774795pfg.13 for ; Tue, 10 Sep 2019 09:09:09 -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=lsF1y/LAf5L+2wQLGdeHEaRtoQrXQNuhBq52QCwbapo=; b=mdVQsy1cW0AfygbqRfmRAt0xnJVqMTwwmQzqbSnqPGSYkZ06kclM5ECyrWQBKM25dT XL8xTcMiEkNA0dzblEd5R9eboXRJ4QoJnyMa6iPUIWJ03wldonWCEuP7hRY3Hr/JSrhO EJ+7hQx8IJ/x/dHNQIuUT96b7SjMfakjzK7co= 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=lsF1y/LAf5L+2wQLGdeHEaRtoQrXQNuhBq52QCwbapo=; b=aRswQf1emUjciIgZictGNP1Cv+w4tP8Ch7OkUfdfxY9SwPIiIu+WZDwVvQFZ21VvKd /SBep5BXx8XiR4gfzZkPFpInBU392WzzI7X0ydfGu+dB6oE7iwNB7yyKxRpntgKOazbL QgLB28nJmA3V189TBxyUaxD/SMI5/8uaQNb6MvLynhJXO2IYcJlC7CzbDolrnIocJw4p qRI7UAtOhK/EU2i9Xzi7v0cOa8sGCTb6506dfog3mpZha1FKKEZF1Bzb7cCHi1kM+9Nx MPhbEw07fmJma+/QTkvL9VrdhkeXV/eODbPfgd2110TRhb+SBf7ZgUZ1gvyEccvYp3Tv 5mLQ== X-Gm-Message-State: APjAAAUxWBl7XMUfn12dDGJoNBuR9pnQvZgCh7FuRyDPfQesgXqhixBR tFc091LphEze4Y3KiY9/wtbhcg== X-Google-Smtp-Source: APXvYqwMeJoUoF1ubTQIVEULDLnsWvGfVPpOgjlnCF8F46XKd3UOlxCsPsfc2H79TqI9334Revht/w== X-Received: by 2002:a17:90a:a002:: with SMTP id q2mr257538pjp.69.1568131749136; Tue, 10 Sep 2019 09:09:09 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id em21sm106088pjb.31.2019.09.10.09.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 09:09:08 -0700 (PDT) From: Stephen Boyd To: Dan Williams Subject: [PATCH v3 5/5] soc: qcom: cmd-db: Map with read-only mappings Date: Tue, 10 Sep 2019 09:09:03 -0700 Message-Id: <20190910160903.65694-6-swboyd@chromium.org> X-Mailer: git-send-email 2.23.0.162.g0b9fbb3734-goog In-Reply-To: <20190910160903.65694-1-swboyd@chromium.org> References: <20190910160903.65694-1-swboyd@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190910_090910_044122_6511D6AA X-CRM114-Status: GOOD ( 14.78 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 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 , linux-kernel@vger.kernel.org, Evan Green , Bjorn Andersson , Rob Herring , Andy Gross , Catalin Marinas , 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 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 Reviewed-by: Bjorn Andersson 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;