Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2356653imm; Thu, 9 Aug 2018 11:26:33 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzfbQhTUUoNbIwiZkPLyTPj/xa56xInjYwGWawPqDpVvbTzkOF0xAD6OK6Arex8nQJB1SPm X-Received: by 2002:a17:902:7147:: with SMTP id u7-v6mr3007600plm.154.1533839193343; Thu, 09 Aug 2018 11:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533839193; cv=none; d=google.com; s=arc-20160816; b=RZEyltA7vGkDIjwHDojqip1jiSUFmuY8awDGTIZ2FDMlGbwBDNtAznHfUJH8hVYeKU Jy9UCHkOW7JONwyMv9+423yZkGil1t8o331sMC6AJGeo7hqBHuHsUi2xqkgB7WPSVwLS eDfhYdUb//x1sLn9pHI1yreLpu1T5SatpRKZBMZLvVfp6h4iofkv7b8CAr7yiT1u4d0x WRJRalu1s0RzHsthQdM5xG3Q8N+MUd8xR48M/la8N9+tY30FcB11yki8gXfuq7P+hhG4 8ay/e/zl50A/8podqu+4ceavHM1H9/jeAsedcORvQrbAWLcTJWtu73C6b5+vC959zuvf M3Wg== 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 :arc-authentication-results; bh=jQiWb8GC3gv+Nn87RzRiath9No2TT7cC5BxoF9sbtxw=; b=tSdb7vKgMnJGsOgUzTxThkXlYy1E4aCdQt3ps4kvOsMcW8Srzx/xwNaGdpSTnZpEej 9QCjHuKnj2AkYDdy6QM9K8jDAI+mmb1vpOkI5uBkCBRp0evP1WDPTuSNH7nT6zhgyf1o dVumyb+QjRwCxwGgqdTZ4bymL2SIu3+pBhQTW/5HQ/kE4VRQgyM/uemViPDq8gulWbXo UAZD85NOGItPLu3dC/js2mOHJ94CblMFu1SL+40i3YlWBcXpalU2rc4TVXv47Mgo0nc7 AhWQCdzG+V99c5H2wkiOfgDsI0kl8iD0g7ZQQR8sgGIrU1e2ri8Wz3z4y34gZ49sugVF brjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WbQUdwOK; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h86-v6si8504569pfj.120.2018.08.09.11.26.18; Thu, 09 Aug 2018 11:26:33 -0700 (PDT) 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=@chromium.org header.s=google header.b=WbQUdwOK; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726944AbeHIUur (ORCPT + 99 others); Thu, 9 Aug 2018 16:50:47 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:45932 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbeHIUur (ORCPT ); Thu, 9 Aug 2018 16:50:47 -0400 Received: by mail-yw1-f65.google.com with SMTP id 139-v6so5761505ywg.12 for ; Thu, 09 Aug 2018 11:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jQiWb8GC3gv+Nn87RzRiath9No2TT7cC5BxoF9sbtxw=; b=WbQUdwOKy/hQMkGcBsUG30dfEV6PQkQBuwf+y9yYKAyzRsfWB0B6zhC0y01nWDrF/h St6MK2tQphdNJAH4dpC2wuiIU+JlzHdhjW1EQVTHntpRTLUNB0owNoZimvYPZ/bN7mBy LONAEk9GC1tqNv65x/9fAKujwWS0mZUyZo5cA= 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=jQiWb8GC3gv+Nn87RzRiath9No2TT7cC5BxoF9sbtxw=; b=tbbWAUJKfD8mJBGAiOdnkUBUSmfQ9Sxpzn1FkxEo3OgEcoNJPdyNMbquGmKvJFpxiW JGG4ggODSWoJZGv/hx7xCD+SpAXt6e0Z9tAVvvpO/U5dN87T7lvA1Nbljnoq1IJSksZb nMHTdF2ItiPBVYgXs57UoztqRJHwGq9nZ/6flG39Wqm99GDAzbH+bic5Ay17vOcAZnGm +DaYlWSxupr0lEhGrlKln6yz+TjRL44jZ1yXWDWW1Pkqilxd/xUnXbqM5E7u3xyNkjCi nCIL0FyQHEB+4nyTGGw33FyFb63swuk3M1EQfLK7poBE4Ioso4WuG/RGkzR8Rw2OpIt/ 4olg== X-Gm-Message-State: AOUpUlE2bWE2liWcTbnqAdF1NLOlMLh8evwe1TmOs1y0Z9Xcn9hlhs9A WETMJ2kFw3cCnVM6wDMsC0aQPPjLhVQ+SeEPscaPVQ== X-Received: by 2002:a1f:f284:: with SMTP id q126-v6mr2108207vkh.38.1533839082279; Thu, 09 Aug 2018 11:24:42 -0700 (PDT) MIME-Version: 1.0 References: <20180809171722.144325-1-swboyd@chromium.org> <20180809171722.144325-6-swboyd@chromium.org> In-Reply-To: <20180809171722.144325-6-swboyd@chromium.org> From: Julius Werner Date: Thu, 9 Aug 2018 11:24:29 -0700 Message-ID: Subject: Re: [PATCH v3 5/7] firmware: coreboot: Remap RAM with memremap() instead of ioremap() To: swboyd@chromium.org, Aaron Durbin Cc: Greg Kroah-Hartman , LKML , Wei-Ning Huang , Julius Werner , Brian Norris , samuel@sholland.org 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 One thing to note is that we still want this space to be mappable by userspace applications via /dev/mem, so we need to make sure that there's no weird memory type mismatch that causes problems with that. Adding Aaron to see if he has any concerns here, since I think he's seen something like that in the past (not sure if it was related to what this kernel driver does). Can you please test this on an x86 Chromebook and run the 'cbmem' userspace utility, make sure it doesn't fail after this? Also, stupid question after taking a step back and looking at this again: why do we keep a mapping alive for the lifetime of the driver at all? It used to be necessary when this driver was find-entry-on-demand, but nowadays it just goes through all entries once at probe time and immediately memcpy_fromio()s out all the relevant information into (struct coreboot_device)s. After that we're done accessing the "real" coreboot table, forever. Why not just unmap it again at the end of coreboot_table_init()? On Thu, Aug 9, 2018 at 10:17 AM Stephen Boyd wrote: > > This is all system memory, so we shouldn't be mapping this all with > ioremap() as these aren't I/O regions. Instead, they're memory regions > so we should use memremap(). Pick MEMREMAP_WB so we can map memory from > RAM directly if that's possible, otherwise it falls back to > ioremap_cache() like is being done here already. This also nicely > silences the sparse warnings in this code and reduces the need to copy > anything around anymore. > > Cc: Wei-Ning Huang > Cc: Julius Werner > Cc: Brian Norris > Cc: Samuel Holland > Signed-off-by: Stephen Boyd > --- > drivers/firmware/google/coreboot_table.c | 42 +++++++++++------------- > 1 file changed, 20 insertions(+), 22 deletions(-) > > diff --git a/drivers/firmware/google/coreboot_table.c b/drivers/firmware/google/coreboot_table.c > index feb31502f64b..f343dbe86448 100644 > --- a/drivers/firmware/google/coreboot_table.c > +++ b/drivers/firmware/google/coreboot_table.c > @@ -32,7 +32,7 @@ > #define CB_DEV(d) container_of(d, struct coreboot_device, dev) > #define CB_DRV(d) container_of(d, struct coreboot_driver, drv) > > -static struct coreboot_table_header __iomem *ptr_header; > +static struct coreboot_table_header *ptr_header; > > static int coreboot_bus_match(struct device *dev, struct device_driver *drv) > { > @@ -94,18 +94,18 @@ void coreboot_driver_unregister(struct coreboot_driver *driver) > } > EXPORT_SYMBOL(coreboot_driver_unregister); > > -static int coreboot_table_init(struct device *dev, void __iomem *ptr) > +static int coreboot_table_init(struct device *dev, void *ptr) > { > int i, ret; > void *ptr_entry; > struct coreboot_device *device; > - struct coreboot_table_entry entry; > - struct coreboot_table_header header; > + struct coreboot_table_entry *entry; > + struct coreboot_table_header *header; > > ptr_header = ptr; > - memcpy_fromio(&header, ptr_header, sizeof(header)); > + header = ptr; > > - if (strncmp(header.signature, "LBIO", sizeof(header.signature))) { > + if (strncmp(header->signature, "LBIO", sizeof(header->signature))) { > pr_warn("coreboot_table: coreboot table missing or corrupt!\n"); > return -ENODEV; > } > @@ -114,11 +114,11 @@ static int coreboot_table_init(struct device *dev, void __iomem *ptr) > if (ret) > return ret; > > - ptr_entry = (void *)ptr_header + header.header_bytes; > - for (i = 0; i < header.table_entries; i++) { > - memcpy_fromio(&entry, ptr_entry, sizeof(entry)); > + ptr_entry = ptr_header + header->header_bytes; > + for (i = 0; i < header->table_entries; i++) { > + entry = ptr_entry; > > - device = kzalloc(sizeof(struct device) + entry.size, GFP_KERNEL); > + device = kzalloc(sizeof(struct device) + entry->size, GFP_KERNEL); > if (!device) { > ret = -ENOMEM; > break; > @@ -128,7 +128,7 @@ static int coreboot_table_init(struct device *dev, void __iomem *ptr) > device->dev.parent = dev; > device->dev.bus = &coreboot_bus_type; > device->dev.release = coreboot_device_release; > - memcpy_fromio(&device->entry, ptr_entry, entry.size); > + memcpy(&device->entry, ptr_entry, entry->size); > > ret = device_register(&device->dev); > if (ret) { > @@ -136,12 +136,12 @@ static int coreboot_table_init(struct device *dev, void __iomem *ptr) > break; > } > > - ptr_entry += entry.size; > + ptr_entry += entry->size; > } > > if (ret) { > bus_unregister(&coreboot_bus_type); > - iounmap(ptr); > + memunmap(ptr); > } > > return ret; > @@ -149,11 +149,10 @@ static int coreboot_table_init(struct device *dev, void __iomem *ptr) > > static int coreboot_table_probe(struct platform_device *pdev) > { > - phys_addr_t phyaddr; > resource_size_t len; > - struct coreboot_table_header __iomem *header = NULL; > + struct coreboot_table_header *header; > struct resource *res; > - void __iomem *ptr = NULL; > + void *ptr; > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > if (!res) > @@ -163,14 +162,13 @@ static int coreboot_table_probe(struct platform_device *pdev) > if (!res->start || !len) > return -EINVAL; > > - phyaddr = res->start; > - header = ioremap_cache(phyaddr, sizeof(*header)); > + header = memremap(res->start, sizeof(*header), MEMREMAP_WB); > if (header == NULL) > return -ENOMEM; > > - ptr = ioremap_cache(phyaddr, > - header->header_bytes + header->table_bytes); > - iounmap(header); > + ptr = memremap(res->start, header->header_bytes + header->table_bytes, > + MEMREMAP_WB); > + memunmap(header); > if (!ptr) > return -ENOMEM; > > @@ -181,7 +179,7 @@ static int coreboot_table_remove(struct platform_device *pdev) > { > if (ptr_header) { > bus_unregister(&coreboot_bus_type); > - iounmap(ptr_header); > + memunmap(ptr_header); > ptr_header = NULL; > } > > -- > Sent by a computer through tubes >