Received: by 10.223.185.116 with SMTP id b49csp2395834wrg; Thu, 15 Feb 2018 10:58:53 -0800 (PST) X-Google-Smtp-Source: AH8x225rsDWGZ4NGKK1TLlaUaQjOi94EJCNP9udNYAxp4kw+5kpUkqSMSbLwVQaF4OuA3cYet/+x X-Received: by 10.98.128.13 with SMTP id j13mr3487412pfd.141.1518721133086; Thu, 15 Feb 2018 10:58:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518721133; cv=none; d=google.com; s=arc-20160816; b=b9vO8VSnVmCzntJNR8QDFT7lw28e+D79MahpZCDw+GsEB1Wzqfs9XM8Q8kv/Jf/r6X 5/a6Uj617yT2OtctKg43k3R/OuJ++5RpDF/g/RrrsjB8sTPXoTN4LuQtj3GMCBAg+rB/ 2U33JUEP+XNLa1id0vonfWRgbLymsLL58hwbri7I/w7Yj9aD+gjZXdO/IKFF1AVCoONG xnYsB7XepKkSIahRJ4KpaNyk2zKUJJ2ZgKB7DhP3Q0UZrx8kMBMs3UQ/6umY4MtprhZI +NcYRn/eT7X+rpc5p1sQpqEvn0LmygTZqQHkxZDVS255zjb6nuCs2jm2CpituQyCaTL5 +k9g== 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=5wqc9am1tyOwAbz3g4ALsOX88eSmuP2xZN7Rr0c0jl4=; b=U0AdKNzAa+O50ShJrcRTsLLsJZ4DZFg6cS8XkJc2Aann63wR9TB+6GIboPjdwNLBtp PhHGbuAMQpVvbioc8e/zomi+OOjQIuABLFFN3I46EYU93nBUwyvzCvUnfkrIu9yrxKjd bWzK8GFU7Wf8XE9kiIWPqLZMpCkAk/pO+iSpO6rNbq4D0fuqHmju4VVBhT8D3iWysXo7 8YEd51fqJvqJYeqmi2Mt49dhp7SYh7ADyB8xYMkAt6tjZ0IVxkzH7gMpNX5TEhaDgZOX kuZEJIIPqhDW0ER3gjqM/enMoKiAUtFl52ZVY1ds+fIaxgZltlFW+yLfBZpRBNSGomPq sr0w== 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 n12si370587pgu.475.2018.02.15.10.58.38; Thu, 15 Feb 2018 10:58:53 -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 S1161487AbeBOPT4 (ORCPT + 99 others); Thu, 15 Feb 2018 10:19:56 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:48076 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033886AbeBOPTw (ORCPT ); Thu, 15 Feb 2018 10:19:52 -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 5A7991072; Thu, 15 Feb 2018 15:19:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rasmus Villemoes , Tejun Heo , Arjan van de Ven , Adam Wallis , Lai Jiangshan , Andrew Morton , Linus Torvalds Subject: [PATCH 3.18 36/45] kernel/async.c: revert "async: simplify lowest_in_progress()" Date: Thu, 15 Feb 2018 16:17:27 +0100 Message-Id: <20180215144123.622093447@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215144115.863307741@linuxfoundation.org> References: <20180215144115.863307741@linuxfoundation.org> User-Agent: quilt/0.65 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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rasmus Villemoes commit 4f7e988e63e336827f4150de48163bed05d653bd upstream. This reverts commit 92266d6ef60c ("async: simplify lowest_in_progress()") which was simply wrong: In the case where domain is NULL, we now use the wrong offsetof() in the list_first_entry macro, so we don't actually fetch the ->cookie value, but rather the eight bytes located sizeof(struct list_head) further into the struct async_entry. On 64 bit, that's the data member, while on 32 bit, that's a u64 built from func and data in some order. I think the bug happens to be harmless in practice: It obviously only affects callers which pass a NULL domain, and AFAICT the only such caller is async_synchronize_full() -> async_synchronize_full_domain(NULL) -> async_synchronize_cookie_domain(ASYNC_COOKIE_MAX, NULL) and the ASYNC_COOKIE_MAX means that in practice we end up waiting for the async_global_pending list to be empty - but it would break if somebody happened to pass (void*)-1 as the data element to async_schedule, and of course also if somebody ever does a async_synchronize_cookie_domain(, NULL) with a "finite" cookie value. Maybe the "harmless in practice" means this isn't -stable material. But I'm not completely confident my quick git grep'ing is enough, and there might be affected code in one of the earlier kernels that has since been removed, so I'll leave the decision to the stable guys. Link: http://lkml.kernel.org/r/20171128104938.3921-1-linux@rasmusvillemoes.dk Fixes: 92266d6ef60c "async: simplify lowest_in_progress()" Signed-off-by: Rasmus Villemoes Acked-by: Tejun Heo Cc: Arjan van de Ven Cc: Adam Wallis Cc: Lai Jiangshan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/async.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/kernel/async.c +++ b/kernel/async.c @@ -84,20 +84,24 @@ static atomic_t entry_count; static async_cookie_t lowest_in_progress(struct async_domain *domain) { - struct list_head *pending; + struct async_entry *first = NULL; async_cookie_t ret = ASYNC_COOKIE_MAX; unsigned long flags; spin_lock_irqsave(&async_lock, flags); - if (domain) - pending = &domain->pending; - else - pending = &async_global_pending; + if (domain) { + if (!list_empty(&domain->pending)) + first = list_first_entry(&domain->pending, + struct async_entry, domain_list); + } else { + if (!list_empty(&async_global_pending)) + first = list_first_entry(&async_global_pending, + struct async_entry, global_list); + } - if (!list_empty(pending)) - ret = list_first_entry(pending, struct async_entry, - domain_list)->cookie; + if (first) + ret = first->cookie; spin_unlock_irqrestore(&async_lock, flags); return ret;