Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1611021pxb; Wed, 10 Feb 2021 12:22:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJw93EkfzU4jNPKMemA3EWviItmA+sBXjovg2hu1YCVs28d7qCxNqAFio8mIiS9ciCo3cxXY X-Received: by 2002:a17:907:2bef:: with SMTP id gv47mr4733391ejc.457.1612988536342; Wed, 10 Feb 2021 12:22:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612988536; cv=none; d=google.com; s=arc-20160816; b=b4dcbgR0dTk5qoRAjEH8RK89yn5XUcTUgNTNmFrb+4MDjhZ9ECVYj2mKFeSzYULCWm ijtftLUntXfRYtnCmo8b1rdx9JsAMRMiofgSkDgm9au5f8jMX3prpiKzEmRaiNJrOab6 SScyvzR+Axr4rbUXJy+XyWeAdgGFniDyWhMm+yGyHhUl2/unAtS5wNi6Mt+vfp09wSwz y+vBjqhjfC4Et0gh8c4Xi4owUiALxOgl3F97jlTsaVbe//ijwJ6v23CeZ+nUi+F2Za0P JacnDPWH/hm+NmrjnfUq+Z0fV5/dmfZvnhaGY1GrVSseKi4iN1akTEvGj+DBBUnPQW+1 TTxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Fvc8yFFiXhssCS/8DtOpvEZDrYQpXuFAX3ho/UHrA28=; b=ITNufV2N6g1O99xanDtgbGQky9BFjFzwfRMccs8nVjlR49BAKJmIMjUo7egCQunKo0 KFQqhtrFso6yjw1neU6I6wahXkFYmN4eWthh9LczxsLqbhQ5zbwl6gm4mWNAG768xh78 WoNFSEQ1a1GpTNziaHzoVRRNK06pxZytrIKbxFwCkIo5sH0ECl2zwTi42Tql4WbSMb5x O3YvzzcxtzMaY8aChyvi5g9njok7iHkiNyqc4VSwmSBuqZ8BqnT46nLH8HQqmp2y10ZN +bR9Sz28zzlMW4QPMseCDE4rHKobSdLDgeDCjFqzq95fyCvmekTvgH5vfQ7KSwuNnnBm 90PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ocZZLVpN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t18si1903232ejc.249.2021.02.10.12.21.49; Wed, 10 Feb 2021 12:22:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ocZZLVpN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232904AbhBJUSY (ORCPT + 99 others); Wed, 10 Feb 2021 15:18:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233011AbhBJUSG (ORCPT ); Wed, 10 Feb 2021 15:18:06 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D809DC0613D6 for ; Wed, 10 Feb 2021 12:17:25 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id c11so2015196pfp.10 for ; Wed, 10 Feb 2021 12:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Fvc8yFFiXhssCS/8DtOpvEZDrYQpXuFAX3ho/UHrA28=; b=ocZZLVpNz8sfpL00VeOLjj4QYmBPgMvR36kniyBJDEiau0zbb+mmw7JH6hte/0Rxvp 5yYKYAxusgX4xn0VYchNl0ijAsJRCWv4Q8fYbwD88Zfg+/nIWw1tgyssijl0FmCCbvnT 8B/ouI3YWCsmDFcg4w0vk8HNGxljob7JUPOIs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Fvc8yFFiXhssCS/8DtOpvEZDrYQpXuFAX3ho/UHrA28=; b=oj0LWPUblaL/c5Z5SFFHFHC4yq9rkUipuULLAW2aKWXcDYwDucGuDZIQi2EcBCirqg Xk83MnTJaeUbXlxwWStXkaA+fH0iUjPeRcN7b4gFumUOFK2Xnb6291irUDjx3xcX+L6s 5K74wsdDtLQfZY5zFjLpv4CURXY8XmJdiZvqIouVPZq+/Yxj+loTwBbgWL92o/yxpy4F F1YzrdIN9lPpC2Jjt1FVtjLzJvv80+MIn5Bh43r/7LjP5cUXtYW+MzZG1MyG5XklI11j KTIQDt9j7JFi9ZxweBua8fqBcXh9UWszAlHlOWTx/I7GUCq+6MoTVd5vXoUlFKb8ylTF Pvvw== X-Gm-Message-State: AOAM530sD+xEfQFsVevzPTfmfYPtRqdReObAP4hgmgaNs6uJjvtSf8W4 yuG7vOx/vSFrNTqThQyGJuuy6A== X-Received: by 2002:a63:686:: with SMTP id 128mr4621480pgg.421.1612988245435; Wed, 10 Feb 2021 12:17:25 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y15sm3077709pju.20.2021.02.10.12.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 12:17:24 -0800 (PST) Date: Wed, 10 Feb 2021 12:17:23 -0800 From: Kees Cook To: Mukesh Ojha Cc: linux-kernel@vger.kernel.org, tony.luck@intel.com, ccross@android.com, anton@enomsg.org, Huang Yiwei Subject: Re: [PATCH] pstore/ram : Add support for cached pages Message-ID: <202102101213.D603669D4@keescook> References: <1612968741-1692-1-git-send-email-mojha@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1612968741-1692-1-git-send-email-mojha@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 10, 2021 at 08:22:21PM +0530, Mukesh Ojha wrote: > There could be a sceanario where we define some region > in normal memory and use them store to logs which is later > retrieved by bootloader during warm reset. > > In this scenario, we wanted to treat this memory as normal > cacheable memory instead of default behaviour which > is an overhead. Making it cacheable could improve > performance. Cool; yeah. I like this idea. > > This commit gives control to change mem_type from Device > tree, and also documents the value for normal memory. What's the safest default setting? > > Signed-off-by: Huang Yiwei > Signed-off-by: Mukesh Ojha > --- > Documentation/admin-guide/ramoops.rst | 4 +++- > fs/pstore/ram.c | 1 + > fs/pstore/ram_core.c | 10 ++++++++-- > 3 files changed, 12 insertions(+), 3 deletions(-) > > diff --git a/Documentation/admin-guide/ramoops.rst b/Documentation/admin-guide/ramoops.rst > index b0a1ae7..8f107d8 100644 > --- a/Documentation/admin-guide/ramoops.rst > +++ b/Documentation/admin-guide/ramoops.rst > @@ -3,7 +3,7 @@ Ramoops oops/panic logger > > Sergiu Iordache > > -Updated: 17 November 2011 > +Updated: 10 Feb 2021 > > Introduction > ------------ > @@ -30,6 +30,8 @@ mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use > depends on atomic operations. At least on ARM, pgprot_noncached causes the > memory to be mapped strongly ordered, and atomic operations on strongly ordered > memory are implementation defined, and won't work on many ARMs such as omaps. > +Setting ``mem_type=2`` attempts to treat the memory region as normal memory, > +which enables full cache on it. This can improve the performance. > > The memory area is divided into ``record_size`` chunks (also rounded down to > power of two) and each kmesg dump writes a ``record_size`` chunk of > diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c > index ca6d8a8..b262c57 100644 > --- a/fs/pstore/ram.c > +++ b/fs/pstore/ram.c > @@ -666,6 +666,7 @@ static int ramoops_parse_dt(struct platform_device *pdev, > field = value; \ > } > > + parse_u32("mem-type", pdata->record_size, pdata->mem_type); This was handled by "unbuffered" above. Can you find a way to resolve potential conflicts between these? > parse_u32("record-size", pdata->record_size, 0); > parse_u32("console-size", pdata->console_size, 0); > parse_u32("ftrace-size", pdata->ftrace_size, 0); > diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c > index aa8e0b6..83cd612 100644 > --- a/fs/pstore/ram_core.c > +++ b/fs/pstore/ram_core.c > @@ -396,6 +396,10 @@ void persistent_ram_zap(struct persistent_ram_zone *prz) > persistent_ram_update_header_ecc(prz); > } > > +#define MEM_TYPE_WCOMBINE 0 > +#define MEM_TYPE_NONCACHED 1 > +#define MEM_TYPE_NORMAL 2 It might be nice for this to have a human-readable name too, but let's start with numeric. :) Please update the mem_type MODULE_PARM_DESC to detail the new values too. > + > static void *persistent_ram_vmap(phys_addr_t start, size_t size, > unsigned int memtype) > { > @@ -409,9 +413,11 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size, > page_start = start - offset_in_page(start); > page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE); > > - if (memtype) > + if (memtype == MEM_TYPE_NORMAL) > + prot = PAGE_KERNEL; > + else if (memtype == MEM_TYPE_NONCACHED) > prot = pgprot_noncached(PAGE_KERNEL); > - else > + else if (memtype == MEM_TYPE_WCOMBINE) > prot = pgprot_writecombine(PAGE_KERNEL); Let's make this a switch statement. > > pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL); > -- > Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, > Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project > -- Kees Cook