Received: by 10.223.185.116 with SMTP id b49csp661139wrg; Fri, 16 Feb 2018 05:15:27 -0800 (PST) X-Google-Smtp-Source: AH8x226Pt4Jyuw6H23Kra4McMfN1zye1KBhvQFsk32gX2gtc/xm5Y1OWkwFVhDm/i3J2qjei/U6e X-Received: by 2002:a17:902:6f17:: with SMTP id w23-v6mr5892280plk.336.1518786927035; Fri, 16 Feb 2018 05:15:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518786926; cv=none; d=google.com; s=arc-20160816; b=RRDA1cBYwBFqF/bvcAqyW0oO/Wqdr2MXTSl6frLnCF4nK6df2muCqnmHsQUYm4NyfE zW/S6BoKbfKbVdFjqDwR4K8GcuxEsCU3ts1K13rlhEMfpLm3FAeD329cuumg2aV6bBCB SU9IuFUcIIxlgYpaD05b65I2xDsuzdIRUqpVYhteD/Qpr4KY9tg0Zbki7FuwTEM117BU Z5hDm7XXdSl/LylZ8ldSpC97Ury2078kn02VwCq8y2UsNNPyCuS0EomGOTF8k0jZPkqn 7DqlJ5GjCeNWJOznHIlWC19wej2fTPz+0ToF5VDBtRTbr1k5XqtwCu8dFWuggO3UxlHn S/JA== 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=jQdZliIbuP1gT1U/oXQ8xOG9hS4Tzh/zmmwp+eEeKOc=; b=BJq66gzPFjkevAbIQC3yIRM75ngvgVlpr40MmKiy0hvnqMu45Pjmlyan8uZ9C82Lxx 8UzPQooyW/ytXCborf3SBygqzfhD6z6R+PUuZyTKc4wZmNFOqjrknJmy985xk70AjS1Z M9sv65f/v7RgTtNK39TxRR9Kb5el0sEAQ3iv0e4pxeLtDHRj+DEz42R2qlmkGiQEOnot K6OCng+Nf2CNi/Po/TTYCTNzPUPm1KNFMdWszLZ5xW9Ur5CSY4S4038/LcBdgR5wHOSr JHCJLt8g/HubRF8WXfSzDe5/cC1WPNy3qQp+i7pZpJm9KXwFPkz22FYTfnxk3lmZjLv/ GDkQ== 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 p1-v6si1342507plb.105.2018.02.16.05.15.11; Fri, 16 Feb 2018 05:15:26 -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 S1166426AbeBOS3n (ORCPT + 99 others); Thu, 15 Feb 2018 13:29:43 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:52190 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163154AbeBOPZU (ORCPT ); Thu, 15 Feb 2018 10:25:20 -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 C038810FD; Thu, 15 Feb 2018 15:25:19 +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 4.4 091/108] kernel/async.c: revert "async: simplify lowest_in_progress()" Date: Thu, 15 Feb 2018 16:17:28 +0100 Message-Id: <20180215151235.075330399@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.267507937@linuxfoundation.org> References: <20180215151222.267507937@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 4.4-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;