Received: by 10.223.185.116 with SMTP id b49csp2209292wrg; Thu, 15 Feb 2018 08:08:32 -0800 (PST) X-Google-Smtp-Source: AH8x226MT4T9iUNcenXE3RhElyFWk9zAxmCChLvsSwynVwwkPEUyVclVU1IeiGc4U8AE81V2SHgD X-Received: by 10.99.122.71 with SMTP id j7mr2566541pgn.151.1518710912070; Thu, 15 Feb 2018 08:08:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518710912; cv=none; d=google.com; s=arc-20160816; b=AXXml61uKCzFXGL42JdBlbpCPnUSaH+ApMaGIaUILfI3+DnarZeV9ANkJHYIE7QRt6 zCWnO1OIRUfKID2VA2exhwnp2csD2iglEu2cy0CJIOIh3EIR2qMFU8OAVNUJ2JC8R79R RmUSGxspbMfahVkmKiM6hWPTyFU/CV8WnJDDJckqsvrs5ji4ELP2oHnvhF0FffcCFgLq Eg3jjyBNqFWMLT6xZP2JohdgeYOCiZDgP5lppKfArT2OaXSpmhsNf9Diqx7PG1NZ2yBl qT+h3vlGw6LKIaWaJWJwGjOhe1Clx897uuyMpA7gjK9t/8u0ldz9ziOWeCMXdshOT924 nvWA== 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=/QokFDUBF0m8Adq1pezowmdXC1ZUQKwoplMOOvv1QiE=; b=GHLxabB9Ix6bi/4kkV+EtZnx2BjnvH8AWsnk0/hfurKkPbQaGPMY8mU1V/rjNFaLN/ hgEjPIn+42Kh/1FMaU4I1Bh4Y6STmDgEwwaFajDdTTZ8iQmIT7mztV/iP6zJ3m25Rw58 H2HhnDIV323OB5cMjopIRhcE7BFGiGaYNgO+KHL6OqSzFve01jDRT6r9on0B65w/L2iG ubKBSxej806U6/p1QB6iKJVaa5pWk5U6GtNd2+u5p+XCevQ5I6uIZjg0D55rnfAXfmWy U4YHR/B5Zd56vZu2rvNwelSEyu4s4WL0jw/6SUW2eFHI56SSGxxSiapSjo9W9+SmkdLy YW+Q== 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 x32-v6si4519692pld.441.2018.02.15.08.08.11; Thu, 15 Feb 2018 08:08:32 -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 S1424566AbeBOPpy (ORCPT + 99 others); Thu, 15 Feb 2018 10:45:54 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35140 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424535AbeBOPpw (ORCPT ); Thu, 15 Feb 2018 10:45: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 50B6411D3; Thu, 15 Feb 2018 15:45: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 4.15 157/202] kernel/async.c: revert "async: simplify lowest_in_progress()" Date: Thu, 15 Feb 2018 16:17:37 +0100 Message-Id: <20180215151721.123971697@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@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.15-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;