Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1336835ybl; Fri, 13 Dec 2019 13:34:15 -0800 (PST) X-Google-Smtp-Source: APXvYqx1v+RrBxwbVtuQwQWauZArXpR+NE0FtUcqVVEKF3eBZKMQN9SBRXt8T0eCQyCb0PWCwBra X-Received: by 2002:a9d:7394:: with SMTP id j20mr17181786otk.273.1576272854990; Fri, 13 Dec 2019 13:34:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576272854; cv=none; d=google.com; s=arc-20160816; b=mecj83taHQYTjxsZ0wYUpSJUUuMYDGSCaQn+o1yJ1Tay9DjUqvMuW0RUvYJH2P/+17 qVkcgF5eaCX1DdgQov3oZ0M6GudUR1Mrd3qqGnfCek/Nj0TRsFPB8jGRVYJqycAh/swF Dnwq9Qgk39VThDO3l2X9m3D9qtcIDsNxhlAsv7quWqP7IvGZaODWPJ5swBhy+fRvj97O dMMda6g4Ufu/zX1j3p0uqQ+wipnch1ABqEBq5lYU0BACJVjmTDdEqCvNfjBIOUFlBq4M 095FQZL2t+pQTvGBH9Jy+hwP9D8ja1xaOQAlyXovxC7s9+pNtQ/4zUaHGkoDe6Tw2DMC XFaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=U7UQIqVTtAUuqjJ6O3IPUORsorWi4L1xwTpqAKgJuaU=; b=m01LqGPIXwrk6zdHklpaPqE/3bEXsB+7F31ICWrOZFPF6hVGYiXJWVRzUOzyXoDI42 NQrk4Dg4zA4oL7f+qBVopmZrgOE1ccrXxgKUbZ6qQmE9Ktpf7FrJOGCps8x5FNS8/wzE g9Pyn0cd6YBotCmITtEozSxr1OU/NhG034fugizBR5jhymYGbu0zwnWqUYIVOVvV8u10 eD3NHBAANAPwibO1QDocuFY1bYedupMmuU5gMUjWTX5WK0fbLgs18DS4tyel+lHq0YVg 5PvDp0DrcGh6zQRwNxGu/wnjYHvjVHZNQtgoG40IUTqUKIeFtr9TgW+48nPR9FResdkr RpGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=k1LMhsGa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p28si6109520oth.296.2019.12.13.13.34.03; Fri, 13 Dec 2019 13:34:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=k1LMhsGa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbfLMVcA (ORCPT + 99 others); Fri, 13 Dec 2019 16:32:00 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:42108 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbfLMVb7 (ORCPT ); Fri, 13 Dec 2019 16:31:59 -0500 Received: by mail-yb1-f196.google.com with SMTP id z10so361515ybr.9 for ; Fri, 13 Dec 2019 13:31:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=U7UQIqVTtAUuqjJ6O3IPUORsorWi4L1xwTpqAKgJuaU=; b=k1LMhsGaHtSh53In008IyDmwqy5ZwYYM27qRr25YGj4IULduelp6jCo6pllVJW4S32 FHA96KboNljrw2wp81a4kAejbfBzn7QRFzchm9pko3Br59mjJHhZ5jLgzsYKKiopEMkk IG5YU97Ed5sceAjRqhTXSe9zyN6aqmDC57TgoClwmNkg2ZfPtHcWq/N/wNY8sQd2MHbP E7PzyRluFW7kLDehjL9WMoI+qbKvFsi8/ScOUWaRWluvikU9cQxR+CnmvWjHBqrP9UDp slECZSmWK0QzQ7coykNv5OQSbifYZ6GoBGXnpqj1jz5TUeXZjvCTZiy5ajcn579I3nXq j2/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=U7UQIqVTtAUuqjJ6O3IPUORsorWi4L1xwTpqAKgJuaU=; b=ReGpglHA2lGnMtQhpQt5vyUuKoY0D33oHCzoTVcc2Qvc850+z/zIWKy+Ya5EVK5Hw3 TYg/tDPZbRFpKcD46490iujLEhvhAIiDr4V+JSM5o9+K++RMTvgx7FfZkxZoJ+UBSfbK njc8izKG8C4imri0l1Dk6IMms9P7qncsBh5u7k801uuC3BS6+fgrAScSEkDapyTT8XdW rkwQZ7Qaz+KUHKPIO8VAwPiGUYBM2NGyzLS6KxNkcJ7FfVWVVIXIpFl3ItKPnSSX5z2G 7UgRqg2ElCp5KOTqK1J/J+AKxvV9HAkBNnMhkw7XilpOFurlFaQojF3jQJMUGYw9+auo cGXg== X-Gm-Message-State: APjAAAVJ2yxxagHeCflcuRRl3cfIcsehprr8+R3IBtIQeF2YDO/sZLAu HT51J/JkqtU6+Y9igMZVC+nfuGJGRGzMwXTAlPPCTXTJMNQ= X-Received: by 2002:a25:75c5:: with SMTP id q188mr7337708ybc.418.1576272718020; Fri, 13 Dec 2019 13:31:58 -0800 (PST) MIME-Version: 1.0 References: <20191128125100.14291-1-patrick.rudolph@9elements.com> <20191128125100.14291-2-patrick.rudolph@9elements.com> In-Reply-To: From: Mat King Date: Fri, 13 Dec 2019 14:31:46 -0700 Message-ID: Subject: Re: [PATCH v3 1/2] firmware: google: Expose CBMEM over sysfs To: Julius Werner Cc: LKML , Greg Kroah-Hartman , Thomas Gleixner , Allison Randal , Alexios Zavras , Stephen Boyd , Samuel Holland Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 9, 2019 at 11:57 PM Julius Werner wrote: > > +static int cbmem_probe(struct coreboot_device *cdev) > > +{ > > + struct device *dev = &cdev->dev; > > + struct cb_priv *priv; > > + int err; > > + > > + priv = kzalloc(sizeof(*priv), GFP_KERNEL); > > + if (!priv) > > + return -ENOMEM; > > + > > + memcpy(&priv->entry, &cdev->cbmem_entry, sizeof(priv->entry)); > > + > > + priv->remap = memremap(priv->entry.address, > > + priv->entry.entry_size, MEMREMAP_WB); > > We've just been discussing some problems with CBMEM areas and memory > mapping types in Chrome OS. CBMEM is not guaranteed to be page-aligned > (at least not the "small" entries), but the kernel can only assign > memory attributes for a page at a time (and refuses to map the same > area twice with two different memory types, for good reason). So if > CBMEM entries sharing a page are mapped as writeback by one driver but > uncached by the other, things break. > > There are some CBMEM entries that need to be mapped uncached (e.g. the > ACPI UCSI table, which isn't even handled by anything using this CBMEM > code) and others for which it would make more sense (e.g. the memory > console, where firmware may add more lines at runtime), but I don't > think there are any regions that really *need* to be writeback. None > of the stuff accessing these areas should access them often enough > that caching matters, and I think it's generally more common to map > firmware memory areas as uncached anyway. So how about we standardize > on mapping it all uncached to avoid any attribute clashes? (That would > mean changing the existing VPD and memconsole drivers to use > ioremap(), too.) I don't think that uncached would work here either because the acpi driver will have already mapped some of these regions as write-back before this driver is loaded so the mapping will fail. Perhaps the best way to make this work is to not call memremap at all in the probe function but instead call memremap and memunmap every time that data_read is called. memremap can take multiple caching mode flags and will try each until one succeeds. So if you call it with MEMREMAP_WB | MEMREMAP_WT in data_read it should succeed no matter how it has been mapped by other drivers which should already be loaded when it is called.