From patchwork Wed Jan 11 03:42:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 9509245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 30BE26075F for ; Wed, 11 Jan 2017 03:42:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21ED3284A3 for ; Wed, 11 Jan 2017 03:42:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1281F284CD; Wed, 11 Jan 2017 03:42:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID,T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CC41284A3 for ; Wed, 11 Jan 2017 03:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754356AbdAKDmU (ORCPT ); Tue, 10 Jan 2017 22:42:20 -0500 Received: from mail-oi0-f66.google.com ([209.85.218.66]:36516 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754179AbdAKDmS (ORCPT ); Tue, 10 Jan 2017 22:42:18 -0500 Received: by mail-oi0-f66.google.com with SMTP id u143so24351827oif.3; Tue, 10 Jan 2017 19:42:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=On2m+x96/ZpYjqHUHGKjNbV8ClqFzUpAqi3sYErEUXY=; b=RpcmZRuQwRJyhWBx0GrrcNnsC7QJay4TCU6iIunX61Y7O88Ni927OJtWEBk8SN8Ic4 WnC04bqdjMUVI6+ZZMT4ROmEztMYila5WtRA1dKGkSQ611odEXk3LCDGwLVT2wY8EnU6 /NB1yU+SLgdxXMaEnWt9s5GIap72UUJOweyahx3zugHLrTSCFmMEwLgLnxJLR8s8YRmg lGusFHvkYHc4d5RqDHm5qQpg+rx4/s8wOBAqtjB02nhwl3B2j3seBBIXdhYkG5jH33nz zARhpixv7YgxyKfq2XwOC4ITWU8MWEyMn7A9rUVs3lEVC9bextVTqGpml0/lnnsiPQYh FWVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=On2m+x96/ZpYjqHUHGKjNbV8ClqFzUpAqi3sYErEUXY=; b=TGL86uCFs7cp1bVovQ0ZmY0e5YFdwkJmozWDdtquJyCzxz18nK4mjOzO26T8e9mc2U /IYgkn+ZcPWH7mtLrA3BloIYA2uh0PgNBuSvx+7GjEwZr1T2XoFcLNQ95OUEDB2VU7hR sxQThEnDiybGohkc5Sk5vbbNQInOEFIaEAMz+DoMEyC4h3uFUXnXRyzHdMHWS4uq0Px9 06I5DuDX8/y4pESBIxnxVQAKIC/l2dOps6mArwQccgWtf9rawhn4BB+zQPNXb3oK239c e7hct4d9vqMOH28Zbci1743Wdc6ZbaSlZnl2iDuikjx+rBj7s5WYzamaRo0sA1v1GYd/ Sysg== X-Gm-Message-State: AIkVDXLA/DfQyDefIHU+LuI07MVpKB+rxIrQ7r1XLEEa9NIAPFY4OR/xBMRclPU29+spckEO392l1pQXpu6W+g== X-Received: by 10.157.41.200 with SMTP id g8mr3343404otd.247.1484106137699; Tue, 10 Jan 2017 19:42:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.12.152 with HTTP; Tue, 10 Jan 2017 19:42:16 -0800 (PST) In-Reply-To: <20170110094122.hpg4sluemkzomeiw@pd.tnic> References: <20170108130355.vxhjmj6dlkqw6hyq@pd.tnic> <1AE640813FDE7649BE1B193DEA596E886CE27B7E@SHSMSX101.ccr.corp.intel.com> <1AE640813FDE7649BE1B193DEA596E886CE27BEE@SHSMSX101.ccr.corp.intel.com> <20170109093329.jd7uwlcpci4icpd3@pd.tnic> <20170109221831.GC3800@linux.vnet.ibm.com> <20170109231501.xrhwsv46mznw3kqt@pd.tnic> <20170109233204.GG3800@linux.vnet.ibm.com> <20170109234039.mfefmv5dv4shxnfn@pd.tnic> <20170109235211.yetponvbexvalkir@pd.tnic> <20170110094122.hpg4sluemkzomeiw@pd.tnic> From: "Rafael J. Wysocki" Date: Wed, 11 Jan 2017 04:42:16 +0100 X-Google-Sender-Auth: GI5yvlho2LDCNw-HFcyohm_tBQ4 Message-ID: Subject: Re: 174cc7187e6f ACPICA: Tables: Back port acpi_get_table_with_size() and early_acpi_os_unmap_memory() from Linux kernel To: Borislav Petkov Cc: "Rafael J. Wysocki" , "Paul E. McKenney" , "Zheng, Lv" , "Wysocki, Rafael J" , "Moore, Robert" , "J?rg R?del" , lkml , Linux ACPI Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Jan 10, 2017 at 10:41 AM, Borislav Petkov wrote: > On Tue, Jan 10, 2017 at 02:27:16AM +0100, Rafael J. Wysocki wrote: >> Well, if the https://patchwork.kernel.org/patch/9504277/ patch from Lv >> worked, the attached one should work too (please test), but it can be >> justified in a slightly more convincing way. > > No workie: > > diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c > index 57fb5f4..acb6118 100644 > --- a/drivers/acpi/osl.c > +++ b/drivers/acpi/osl.c > @@ -378,7 +378,11 @@ static void acpi_os_drop_map_ref(struct acpi_ioremap *map) > static void acpi_os_map_cleanup(struct acpi_ioremap *map) > { > if (!map->refcount) { > - synchronize_rcu_expedited(); > + if (acpi_os_initialized) { > + pr_err("%s: acpi_os_initialized\n", __func__); > + synchronize_rcu_expedited(); > + } > + > acpi_unmap(map->phys, map->virt); > kfree(map); > } > > The pr_err() gets issued before the box hangs. > > Lv's version which set the bool in acpi_os_map_generic_address() did > work though. Well, it would if nothing mapped by acpi_os_map_generic_address() was in the memory address space, for example, but then it would never use the RCU synchronization as well (not good). Basically, we need to find a point during the initialization such that acpi_os_read/write_memory() is not invoked earlier and set a flag in there. Let's try the attached one. BTW, I'm going to travel to the LCA starting tomorrow, so I guess I will be a bit unresponsive during the next few days. Thanks, Rafael --- drivers/acpi/bus.c | 6 ++++++ drivers/acpi/osl.c | 9 ++++++++- include/acpi/acpi_io.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) Index: linux-pm/drivers/acpi/bus.c =================================================================== --- linux-pm.orig/drivers/acpi/bus.c +++ linux-pm/drivers/acpi/bus.c @@ -1191,6 +1191,12 @@ static int __init acpi_init(void) acpi_kobj = NULL; } + /* + * acpi_os_read_memory()/acpi_os_write_memory() should not be invoked + * before this point. + */ + acpi_sync_memory_unmap = true; + init_acpi_device_notify(); result = acpi_bus_init(); if (result) { Index: linux-pm/drivers/acpi/osl.c =================================================================== --- linux-pm.orig/drivers/acpi/osl.c +++ linux-pm/drivers/acpi/osl.c @@ -77,6 +77,7 @@ static struct workqueue_struct *kacpi_ho static bool acpi_os_initialized; unsigned int acpi_sci_irq = INVALID_ACPI_IRQ; bool acpi_permanent_mmap = false; +bool acpi_sync_memory_unmap; /* * This list of permanent mappings is for memory that may be accessed from @@ -378,7 +379,9 @@ static void acpi_os_drop_map_ref(struct static void acpi_os_map_cleanup(struct acpi_ioremap *map) { if (!map->refcount) { - synchronize_rcu_expedited(); + if (acpi_sync_memory_unmap) + synchronize_rcu_expedited(); + acpi_unmap(map->phys, map->virt); kfree(map); } @@ -671,6 +674,8 @@ acpi_os_read_memory(acpi_physical_addres bool unmap = false; u64 dummy; + WARN_ON_ONCE(!acpi_sync_memory_unmap); + rcu_read_lock(); virt_addr = acpi_map_vaddr_lookup(phys_addr, size); if (!virt_addr) { @@ -716,6 +721,8 @@ acpi_os_write_memory(acpi_physical_addre unsigned int size = width / 8; bool unmap = false; + WARN_ON_ONCE(!acpi_sync_memory_unmap); + rcu_read_lock(); virt_addr = acpi_map_vaddr_lookup(phys_addr, size); if (!virt_addr) { Index: linux-pm/include/acpi/acpi_io.h =================================================================== --- linux-pm.orig/include/acpi/acpi_io.h +++ linux-pm/include/acpi/acpi_io.h @@ -14,6 +14,7 @@ static inline void __iomem *acpi_os_iore #endif extern bool acpi_permanent_mmap; +extern bool acpi_sync_memory_unmap; void __iomem *__ref acpi_os_map_iomem(acpi_physical_address phys, acpi_size size);