Received: by 10.223.185.116 with SMTP id b49csp1136319wrg; Fri, 23 Feb 2018 12:34:29 -0800 (PST) X-Google-Smtp-Source: AH8x227Gqbq8ahD7B6jk8e1Mq9EFNLM3uAu3sgsObO4XaHNBwaMjWBPtxJ3psmt/O1IHWIhKR0JO X-Received: by 2002:a17:902:8489:: with SMTP id c9-v6mr2745480plo.439.1519418069885; Fri, 23 Feb 2018 12:34:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519418069; cv=none; d=google.com; s=arc-20160816; b=lHsrRglzOsGllCAns0ca1PI0FF/JmWFYuZy3InM96CvMfzVdIe63X3GQk45AKU2c1D 3/CSulcsFVLXK2bWkwaS8JEfmh4esqhPbDgQX71u4GXogxVBkwwffm40K7lklBz65g3i Rl2Bt7lruzdrrAHQvS/EXdEFKBsg0cyL8VDlBDLdYmfnbZO90e8qGEuBsm+083/CVHly 3Oloh9YIGf2bNCclD2tOE35h03hxZiuGVNhmhqbcsKTqD8SMHlMmSjKkRgGzEf+HW092 xjgztdiBhNxjqWXTkMWqZl++c9nHivanqYcB8Ysz9HgDBbF3q8paGMogXx2xiNQBqJmO cgLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=w+JU5RV7KnYAT2gPQDiCqeBhb30Xa3UGQXJC3de36Xo=; b=noxwweruryqirvW/LQ0x3MHaDjzxSjoXYK2fGM1cEbNj5THbL6MTlgHyqssChLE7/E obpoDAr4O8bbmQVIGHcoXZeHmvMTKuf7s1ajVyOGBdrd54hzEapws9YERtlKbG/NepDg vXdKPq+AIuwOm6VpUzCKqXF2lKcRRj5++2O6joQauK7ZyRNbeW7TZCnAnjuoWIa24zjZ pJRj0K9DAMHYbRvPdrm7bAa8TPruZN7H/RwovkbfAwuu3H6ITCBTi+usziuXahVaPQY8 Ue0vR4w1ywQKht4H5d8fEYFSIsauXPraxi6ht/FlfdiXt9F3UUtDfSDQ6yTGY5x3Ih/D yHXQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si1948299pgn.571.2018.02.23.12.34.15; Fri, 23 Feb 2018 12:34:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753933AbeBWUdi (ORCPT + 99 others); Fri, 23 Feb 2018 15:33:38 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37280 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753209AbeBWSfW (ORCPT ); Fri, 23 Feb 2018 13:35:22 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C891B124C; Fri, 23 Feb 2018 18:35:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lyude , Karol Herbst , Pekka Paalanen , Linus Torvalds , Peter Zijlstra , Steven Rostedt , Thomas Gleixner , nouveau@lists.freedesktop.org, Ingo Molnar , Sasha Levin Subject: [PATCH 4.4 059/193] x86/mm/kmmio: Fix mmiotrace for page unaligned addresses Date: Fri, 23 Feb 2018 19:24:52 +0100 Message-Id: <20180223170335.220215513@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Karol Herbst [ Upstream commit 6d60ce384d1d5ca32b595244db4077a419acc687 ] If something calls ioremap() with an address not aligned to PAGE_SIZE, the returned address might be not aligned as well. This led to a probe registered on exactly the returned address, but the entire page was armed for mmiotracing. On calling iounmap() the address passed to unregister_kmmio_probe() was PAGE_SIZE aligned by the caller leading to a complete freeze of the machine. We should always page align addresses while (un)registerung mappings, because the mmiotracer works on top of pages, not mappings. We still keep track of the probes based on their real addresses and lengths though, because the mmiotrace still needs to know what are mapped memory regions. Also move the call to mmiotrace_iounmap() prior page aligning the address, so that all probes are unregistered properly, otherwise the kernel ends up failing memory allocations randomly after disabling the mmiotracer. Tested-by: Lyude Signed-off-by: Karol Herbst Acked-by: Pekka Paalanen Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Thomas Gleixner Cc: nouveau@lists.freedesktop.org Link: http://lkml.kernel.org/r/20171127075139.4928-1-kherbst@redhat.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/ioremap.c | 4 ++-- arch/x86/mm/kmmio.c | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -348,11 +348,11 @@ void iounmap(volatile void __iomem *addr (void __force *)addr < phys_to_virt(ISA_END_ADDRESS)) return; + mmiotrace_iounmap(addr); + addr = (volatile void __iomem *) (PAGE_MASK & (unsigned long __force)addr); - mmiotrace_iounmap(addr); - /* Use the vm area unlocked, assuming the caller ensures there isn't another iounmap for the same address in parallel. Reuse of the virtual address is prevented by --- a/arch/x86/mm/kmmio.c +++ b/arch/x86/mm/kmmio.c @@ -434,17 +434,18 @@ int register_kmmio_probe(struct kmmio_pr unsigned long flags; int ret = 0; unsigned long size = 0; + unsigned long addr = p->addr & PAGE_MASK; const unsigned long size_lim = p->len + (p->addr & ~PAGE_MASK); unsigned int l; pte_t *pte; spin_lock_irqsave(&kmmio_lock, flags); - if (get_kmmio_probe(p->addr)) { + if (get_kmmio_probe(addr)) { ret = -EEXIST; goto out; } - pte = lookup_address(p->addr, &l); + pte = lookup_address(addr, &l); if (!pte) { ret = -EINVAL; goto out; @@ -453,7 +454,7 @@ int register_kmmio_probe(struct kmmio_pr kmmio_count++; list_add_rcu(&p->list, &kmmio_probes); while (size < size_lim) { - if (add_kmmio_fault_page(p->addr + size)) + if (add_kmmio_fault_page(addr + size)) pr_err("Unable to set page fault.\n"); size += page_level_size(l); } @@ -527,19 +528,20 @@ void unregister_kmmio_probe(struct kmmio { unsigned long flags; unsigned long size = 0; + unsigned long addr = p->addr & PAGE_MASK; const unsigned long size_lim = p->len + (p->addr & ~PAGE_MASK); struct kmmio_fault_page *release_list = NULL; struct kmmio_delayed_release *drelease; unsigned int l; pte_t *pte; - pte = lookup_address(p->addr, &l); + pte = lookup_address(addr, &l); if (!pte) return; spin_lock_irqsave(&kmmio_lock, flags); while (size < size_lim) { - release_kmmio_fault_page(p->addr + size, &release_list); + release_kmmio_fault_page(addr + size, &release_list); size += page_level_size(l); } list_del_rcu(&p->list);