From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754711AbcKJBNV (ORCPT ); Wed, 9 Nov 2016 20:13:21 -0500 Received: from mga05.intel.com ([192.55.52.43]:33026 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752580AbcKJBNU (ORCPT ); Wed, 9 Nov 2016 20:13:20 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,616,1473145200"; d="scan'208";a="1083123152" Subject: Re: [PATCH v4 1/4] usb: dbc: early driver for xhci debug capability To: Thomas Gleixner References: <1477976354-13291-1-git-send-email-baolu.lu@linux.intel.com> <1477976354-13291-2-git-send-email-baolu.lu@linux.intel.com> Cc: Greg Kroah-Hartman , Mathias Nyman , Ingo Molnar , linux-usb@vger.kernel.org, x86@kernel.org, LKML , Peter Zijlstra From: Lu Baolu Message-ID: <5823C9AC.7050209@linux.intel.com> Date: Thu, 10 Nov 2016 09:13:16 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 11/09/2016 05:23 PM, Thomas Gleixner wrote: > On Tue, 1 Nov 2016, Lu Baolu wrote: >> +static int __init xdbc_init(void) >> +{ > ... >> + base = ioremap_nocache(xdbc.xhci_start, xdbc.xhci_length); >> + if (!base) { >> + xdbc_trace("failed to remap the io address\n"); >> + ret = -ENOMEM; >> + goto free_and_quit; >> + } >> + >> + early_iounmap(xdbc.xhci_base, xdbc.xhci_length); >> + xdbc_trace("early mapped IO address released\n"); >> + >> + xdbc.xhci_base = base; >> + offset = xhci_find_next_ext_cap(xdbc.xhci_base, 0, XHCI_EXT_CAPS_DEBUG); >> + xdbc.xdbc_reg = (struct xdbc_regs __iomem *)(xdbc.xhci_base + offset); > This is broken. What prevents that > > - a printk is in progress on another cpu? > > - a printk happens between the unmap and storing the new base ? > > Nothing AFAICT. So this needs to be done in a safe way. And just making it > > oldbase = xdbc.xhci_base; > base = ioremap(....); > xdbc.xhci_base = base; > early_iounmap(oldbase); > > does not work either because the compiler can rightfully cache > xdbc.xhci_base in the write related functions. The same issue with > xdbc.xdbc_reg. If there isn't a good solution, I will remove the ioremap code and let it use the early mapped one. Best regards, Lu Baolu