Received: by 10.213.65.68 with SMTP id h4csp714372imn; Fri, 6 Apr 2018 07:43:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx49BjO4gNA1TZIJl83+gJZTDxifkhCt4uSawo5+MUyovBtkYjt40xU6NKUbTzD/ahLXwtRD9 X-Received: by 10.98.236.86 with SMTP id k83mr20646650pfh.84.1523025819049; Fri, 06 Apr 2018 07:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523025819; cv=none; d=google.com; s=arc-20160816; b=gB+jIrgQiK2ti3WV+cK2q/NHCOxebtm8J73X2lU+twwaveGxoT6iAXnQxpcWg2Hwme GvBCeaLui97GyVACTTNyeKfNCQgBHpLU4SJC+9n9/AehRYG5ziZGPFeVMBk6Bz2N0309 XCdPd5Zxm+AQ6qFkkQmWIskzU2x6587eNbCDHRd8pHPcGKF0L+pOW3JdLjKNcxIhWzz1 GNACNaEPkZT9BSAXNDB4ipKz6wqQ8bK7TYm/AkYlBavWVA7CmcuJLp+8Tp/8uDydwONi 4wtw3oQIwLxITNnDtVFAOLvCcEPg5b5tdKvB6dwCgTaUNQRmX6atI78nkVnH3WB+Jq3I wJ9Q== 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=Z0fSiGuNtO7VL71JN5K5o+93B0iOdNz7qOFW+3eXBY8=; b=HRvpDhDr5RhS6eKu4B8brh4X8e25rk6grOXrGFxwWBekZxxdkufQHkzFbWtlINlyAn qRF0Rjxl677a01tZibgsVAvaHiFbIHt8TGFGAzSex2GCVKdCh/7kPRlZ5HUzBvmKk3cP K9RWEI+Nq+Smr4kp3EsaoDgsW+e5QQ2mE70q/sdritoozTjXJvGC3l2GLIxWATSDhk5i wj7gPAwJbqqx/8NLAHuhk9qEeho0ORC3sb6XSsKMIll9QvcQ/dpswrwsR0OPV6PFzKT5 9cnwcB0Vix8csyqweNwJUXDmiDFO2g93df1+C2ZTSOd/HRuLS74h5jN1yIF8p9KQy+ky vFeg== 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 u23-v6si9468622plk.516.2018.04.06.07.43.25; Fri, 06 Apr 2018 07:43:39 -0700 (PDT) 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 S1755866AbeDFNe1 (ORCPT + 99 others); Fri, 6 Apr 2018 09:34:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58310 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755856AbeDFNeZ (ORCPT ); Fri, 6 Apr 2018 09:34:25 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 29A0BD8A; Fri, 6 Apr 2018 13:34:25 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Potapenko , Sodagudi Prasad , Linus Torvalds Subject: [PATCH 4.9 047/102] llist: clang: introduce member_address_is_nonnull() Date: Fri, 6 Apr 2018 15:23:28 +0200 Message-Id: <20180406084338.255456847@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084331.507038179@linuxfoundation.org> References: <20180406084331.507038179@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Potapenko commit beaec533fc2701a28a4d667f67c9f59c6e4e0d13 upstream. Currently llist_for_each_entry() and llist_for_each_entry_safe() iterate until &pos->member != NULL. But when building the kernel with Clang, the compiler assumes &pos->member cannot be NULL if the member's offset is greater than 0 (which would be equivalent to the object being non-contiguous in memory). Therefore the loop condition is always true, and the loops become infinite. To work around this, introduce the member_address_is_nonnull() macro, which casts object pointer to uintptr_t, thus letting the member pointer to be NULL. Signed-off-by: Alexander Potapenko Tested-by: Sodagudi Prasad Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/llist.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) --- a/include/linux/llist.h +++ b/include/linux/llist.h @@ -88,6 +88,23 @@ static inline void init_llist_head(struc container_of(ptr, type, member) /** + * member_address_is_nonnull - check whether the member address is not NULL + * @ptr: the object pointer (struct type * that contains the llist_node) + * @member: the name of the llist_node within the struct. + * + * This macro is conceptually the same as + * &ptr->member != NULL + * but it works around the fact that compilers can decide that taking a member + * address is never a NULL pointer. + * + * Real objects that start at a high address and have a member at NULL are + * unlikely to exist, but such pointers may be returned e.g. by the + * container_of() macro. + */ +#define member_address_is_nonnull(ptr, member) \ + ((uintptr_t)(ptr) + offsetof(typeof(*(ptr)), member) != 0) + +/** * llist_for_each - iterate over some deleted entries of a lock-less list * @pos: the &struct llist_node to use as a loop cursor * @node: the first entry of deleted list entries @@ -121,7 +138,7 @@ static inline void init_llist_head(struc */ #define llist_for_each_entry(pos, node, member) \ for ((pos) = llist_entry((node), typeof(*(pos)), member); \ - &(pos)->member != NULL; \ + member_address_is_nonnull(pos, member); \ (pos) = llist_entry((pos)->member.next, typeof(*(pos)), member)) /** @@ -143,7 +160,7 @@ static inline void init_llist_head(struc */ #define llist_for_each_entry_safe(pos, n, node, member) \ for (pos = llist_entry((node), typeof(*pos), member); \ - &pos->member != NULL && \ + member_address_is_nonnull(pos, member) && \ (n = llist_entry(pos->member.next, typeof(*n), member), true); \ pos = n)