Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1155094imu; Tue, 11 Dec 2018 13:44:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/VfTVS7dBWknKxeNL4oiCtGg3xJQOhhdVrk5AksTyzvtkYdtkpyXr+NfTSrVvik9i0L1GSQ X-Received: by 2002:a62:9f01:: with SMTP id g1mr17833238pfe.223.1544564690022; Tue, 11 Dec 2018 13:44:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544564689; cv=none; d=google.com; s=arc-20160816; b=l2nfzf3Q1IIcjosSYIxtIZhW3zUSXoUFYxsAIloaXInH7nPRRzMtU+5DdDbKtFsqwZ hOYb01jE0iz9+hLg2Hmy1JHfJuT4Rtq0rV0dV2qU1TXDOKItY+IHJa3yZPcRYSmEqw+j GP/T9xL+rxK8oD63omiyTYOWvmVcc99OtouMzrRdu/jDqOCPMHNSsQYDoBYmmTds8FbB AP1a0G0tCnrfqN9YI6XviHokYSmtul380H7gt11loOwgtjYCIhxJ3dG0eh3CpRvY+3p9 luzZ0hr5EwW9g2Q4XxIH0ubQCCquiCNE3MHgsyg+6bqKVtu4KDlofqHSGYIDFWbU0d+/ rqiQ== 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 :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=dWgfMDWV1IUCMHNHRgEPbsME14kniNDDzpoHAd7Dhkk=; b=ZUClElu/ZYQAFvhbNeYzpopmvq+slhYsB/mphPSXgoVUVmr4CNSq9NHUARwrYZKPy6 2krs5cps60ReCjD6VuaQUI7lDGix2gktfmfh6ZsGE60nqO7mm0UzMKnmdx9Ck+MuKHzu ThF+tkcV77ZqYkPN857YPU9kZry2+vf6jQ8OeXAgECErG5kR10VE//a5ZgGqA12f9+ZS q4L5zZLNsaWxDci8CFVPK4abOfS7hojpULLieFtFfHJ527K8NbxWCXYyTslIhdtybRCz CxHBBVmlj5aO5StwUVQ7HRd/mDlejq3IHO5yQ2rH5c91J75AyjtTpTjsQvVkfPjTdsrl ksDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HAZ1NTRg; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t75si13759466pfi.193.2018.12.11.13.44.34; Tue, 11 Dec 2018 13:44:49 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=HAZ1NTRg; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726240AbeLKVn1 (ORCPT + 99 others); Tue, 11 Dec 2018 16:43:27 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40616 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbeLKVn1 (ORCPT ); Tue, 11 Dec 2018 16:43:27 -0500 Received: by mail-pf1-f196.google.com with SMTP id i12so7755826pfo.7 for ; Tue, 11 Dec 2018 13:43:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=dWgfMDWV1IUCMHNHRgEPbsME14kniNDDzpoHAd7Dhkk=; b=HAZ1NTRgLsatAIqShWvARw64fB2+VYIMs+BQ+PEFXkskK86U/e0+FoqgpTzrl5vs1M /E4kRFwXFFnvdeLNnJ/6tNQAag0JlaYSHQ9xXLlU+hog/q3DXkpsYafRY7cJ/v+cKnA8 MWwqdK/00FON2Ei5AwaFtW0jqcvodJvUMlrv5p5qHsPyz3qezGoTLeNl619UjHTQFPev Cw8Clj64p2HC6BeVaZGIDJGbfCwudfAfTumMd5jvV/T9mij2mK27quRlkV4WVIYaMWvA w1R3MXqPI+73SjLAGQZIY/nFVeRGjhquq/pkQscCs22/vgR0c10pOiJnCZM7T3jNQIQp t8ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=dWgfMDWV1IUCMHNHRgEPbsME14kniNDDzpoHAd7Dhkk=; b=K/7n70bjn9dJckA57/Xz+0mof5boRg8Kxy5uL+9//WVWCn77K+0nY4S4VEKTfaV128 XHhIqLgZTajOGj3gJzDFRc/HFDhhH4OKMeTup8jxhYDejfvdkZm5eZZnwM7ujqQYXgBF DZnBpxsNKb86ipJUNCeAhKT5j/+UoWzIrH1CxtXiTqqHG+Q5F6B+4L+eDi4p1XGzP8+A 780nX8ABw3iBNXWoTDmV3DmW0bcWubD2pd9si8M30fPWfYcj4/y1B4Y/Bm9usPc+Vw+C S+jcNHF0XNAnxgNCbRf3wfcozBxDEg4ksBBqz8NZmfR/CPUXXboUpoaFqsZJ046j8ICk A30g== X-Gm-Message-State: AA+aEWZx1YqH5My1AGUgWzYPYWfczCCarrrH4qYPSuZ3k+H4S7VFKHSj 3I2kwveP2N/HsvHOThpR92foDq8fpmD/jg== X-Received: by 2002:a63:dc54:: with SMTP id f20mr16267142pgj.410.1544564606260; Tue, 11 Dec 2018 13:43:26 -0800 (PST) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id 79sm20001923pge.66.2018.12.11.13.43.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Dec 2018 13:43:25 -0800 (PST) Date: Tue, 11 Dec 2018 13:43:24 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Jerome Glisse cc: Arnd Bergmann , Andrew Morton , Stephen Rothwell , Michal Hocko , Mike Rapoport , linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/mmu_notifier: fix mmu_notifier_range_init warning In-Reply-To: <20181211213636.GB6478@redhat.com> Message-ID: References: <20181211200526.3868586-1-arnd@arndb.de> <20181211201909.GA6478@redhat.com> <20181211213636.GB6478@redhat.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 11 Dec 2018, Jerome Glisse wrote: > > > > The macro version of mmu_notifier_range_init() for CONFIG_MMU_NOTIFIER=n > > > > does not evaluate all its arguments, leading to a warning in one case: > > > > > > > > mm/migrate.c: In function 'migrate_vma_pages': > > > > mm/migrate.c:2711:20: error: unused variable 'mm' [-Werror=unused-variable] > > > > struct mm_struct *mm = vma->vm_mm; > > > > > > > > Pass down the 'mm' as into the inline function as well so gcc can > > > > see why the variable exists. > > > > > > > > Fixes: 137d92bd73b1 ("mm/mmu_notifier: use structure for invalidate_range_start/end calls v2") > > > > > > What about changing migrate.c (i actualy tried to do that everywhere in > > > the patchset but i missed that spot) So we avoid one useless variable on > > > such configuration: > > > > > > diff --git a/mm/migrate.c b/mm/migrate.c > > > index f02bb4b22c1a..883fce631f47 100644 > > > --- a/mm/migrate.c > > > +++ b/mm/migrate.c > > > @@ -2701,7 +2701,6 @@ static void migrate_vma_pages(struct migrate_vma *migrate) > > > const unsigned long npages = migrate->npages; > > > const unsigned long start = migrate->start; > > > struct vm_area_struct *vma = migrate->vma; > > > - struct mm_struct *mm = vma->vm_mm; > > > struct mmu_notifier_range range; > > > unsigned long addr, i; > > > bool notified = false; > > > @@ -2724,8 +2723,8 @@ static void migrate_vma_pages(struct migrate_vma *migrate) > > > if (!notified) { > > > notified = true; > > > > > > - mmu_notifier_range_init(&range, mm, addr, > > > - migrate->end, > > > + mmu_notifier_range_init(&range, vma->vm_mm, > > > + addr, migrate->end, > > > MMU_NOTIFY_CLEAR); > > > mmu_notifier_invalidate_range_start(&range); > > > } > > > > Wouldn't it be better to just declare mmu_notifier_range_init() as a > > static inline function rather than a #define to avoid this warning? > > The define trick is use to drop the event parameter so that we do not > need to define the event value for CONFIG_MMU_NOTIFIER=n case. > Hmm, strange that Arnd's build failure is only reporting about an unused variable instead of MMU_NOTIFY_CLEAR being undefined :/ I think this should be done so that anybody using mmu_notifier_range_init() doesn't need to worry about the implications of *any* unused formal parameter as a result of how the #define is formed: diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -10,21 +10,6 @@ struct mmu_notifier; struct mmu_notifier_ops; -#ifdef CONFIG_MMU_NOTIFIER - -/* - * The mmu notifier_mm structure is allocated and installed in - * mm->mmu_notifier_mm inside the mm_take_all_locks() protected - * critical section and it's released only when mm_count reaches zero - * in mmdrop(). - */ -struct mmu_notifier_mm { - /* all mmu notifiers registerd in this mm are queued in this list */ - struct hlist_head list; - /* to serialize the list modifications and hlist_unhashed */ - spinlock_t lock; -}; - /** * enum mmu_notifier_event - reason for the mmu notifier callback * @MMU_NOTIFY_UNMAP: either munmap() that unmap the range or a mremap() that @@ -53,6 +38,21 @@ enum mmu_notifier_event { MMU_NOTIFY_SOFT_DIRTY, }; +#ifdef CONFIG_MMU_NOTIFIER + +/* + * The mmu notifier_mm structure is allocated and installed in + * mm->mmu_notifier_mm inside the mm_take_all_locks() protected + * critical section and it's released only when mm_count reaches zero + * in mmdrop(). + */ +struct mmu_notifier_mm { + /* all mmu notifiers registerd in this mm are queued in this list */ + struct hlist_head list; + /* to serialize the list modifications and hlist_unhashed */ + spinlock_t lock; +}; + struct mmu_notifier_range { struct mm_struct *mm; unsigned long start; @@ -483,9 +483,14 @@ static inline void _mmu_notifier_range_init(struct mmu_notifier_range *range, range->end = end; } -#define mmu_notifier_range_init(range, mm, start, end, event) \ - _mmu_notifier_range_init(range, start, end) - +static inline void mmu_notifier_range_init(struct mmu_notifier_range *range, + struct mm_struct *mm, + unsigned long start, + unsigned long end, + enum mmu_notifier_event event) +{ + _mmu_notifier_range_init(range, start, end); +} static inline int mm_has_notifiers(struct mm_struct *mm) {