Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7298074rwr; Tue, 2 May 2023 12:25:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4z2R1IfpzI4y915FwWcJaojBp/esC4q2oMp34lXwVYGVyzn8f6Be7DMJbV933idsDJDCgF X-Received: by 2002:a17:90a:318c:b0:24e:1f5:2e05 with SMTP id j12-20020a17090a318c00b0024e01f52e05mr7826397pjb.13.1683055507615; Tue, 02 May 2023 12:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683055507; cv=none; d=google.com; s=arc-20160816; b=FJw+9q1LeXQ5liwlCcs4+8cdfioIxZPuwG9xzjxqd3caIkG/e4Zgf2JsMqg9gh8IJp 0r7WOxDMRDF3u9SzxLfQWCMCF+S/YIBIjhcs/VCYc4OJLExNpGGxeYm5G8HOz5rqIIdb zKrbfSoYgiJXC603syGGYV37Tt2vhLoPreHBXiSRh4ft/WHFxnU06DHbxRo9xBlcP7SN 4z/0pvfLuo6HRKOZq71JaNEaclroeTeTsP1FV0LyCWINdijDE0JudO2PA8sLsgA3O1HC oiQYw2KtjGisyhhwhp3nGY4hq/jEze+Ka3c9/VUOyLT6NIuFA3JuMCuaNy0lhCJiEvHb iBxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=VVhO95ZcNfkC8k06uAz1xAu9kr8Rbpp/4ec2MKvB35g=; b=bZyL/BIoImtxgdDILKQs79SOepijeFDbG5Ys0VjlSWQRkN0cmDAtyvAZxqExjqakqV LiyVIHNrWh10OKlPZ8xtQzs93ZE9f/EBGwbQjr4Qo5yc6zzZsHRGx9SXLarUtSq/0t19 nezqhgv+IoQXs8eBv8YjFaatWCFZtfp+Kslqvcw2QXqQ1+h2WL2ZP023N3QbNK6goXPU Acwalkgh3O9lXumi8yV7C5QQ5xnJnqsvVz/cL1HV95yl+bKRBQZfRU93ELNdA4CA3hRP dIJLrx5DSs9ATI9CpFo/Az7avfYDLF/m6ATfo9jLLS/R+12n+bV0iYLws4usXHgXpM88 CA5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=qg6+vslt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lp14-20020a17090b4a8e00b00247a0928f5dsi25402747pjb.184.2023.05.02.12.24.52; Tue, 02 May 2023 12:25:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=qg6+vslt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbjEBTP3 (ORCPT + 99 others); Tue, 2 May 2023 15:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjEBTP2 (ORCPT ); Tue, 2 May 2023 15:15:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7664D1BD4 for ; Tue, 2 May 2023 12:15:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 122C962071 for ; Tue, 2 May 2023 19:15:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F551C4339B; Tue, 2 May 2023 19:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1683054926; bh=r8WWjkIMJIaq0ut5/ios1bJTm+k1wBFfceoqsar6VsM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qg6+vslt/PZ2KiRJz8sltxAlarRY+0m4mwAxTUhOyxfJCF8bpSFxmxyYqETIAktFb aNnUkECRskkjEWWSWkjFdGtMxAJ6pVGIDqCP/oQ4YLLqsOLdzBam6uEZAUTYDaufve 9ANJ2AMqCAFygybwaTV9MAomqhHeSE/IvEgJGM+w= Date: Tue, 2 May 2023 12:15:25 -0700 From: Andrew Morton To: Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R . Howlett" , Vlastimil Babka Subject: Re: [PATCH] mm/mmap/vma_merge: always check invariants Message-Id: <20230502121525.258f089cbed7e44c113f2d83@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 30 Apr 2023 21:19:17 +0100 Lorenzo Stoakes wrote: > We may still have inconsistent input parameters even if we choose not to > merge and the vma_merge() invariant checks are useful for checking this > with no production runtime cost (these are only relevant when > CONFIG_DEBUG_VM is specified). > > Therefore, perform these checks regardless of whether we merge. > > This is relevant, as a recent issue (addressed in commit "mm/mempolicy: > Correctly update prev when policy is equal on mbind") in the mbind logic > was only picked up in the 6.2.y stable branch where these assertions are > performed prior to determining mergeability. > > Had this remained the same in mainline this issue may have been picked up > faster, so moving forward let's always check them. > I'll scoot this into 6.4-rc, given the recent problems in this area. > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -960,17 +960,17 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, > merge_next = true; > } > > + /* Verify some invariant that must be enforced by the caller. */ > + VM_WARN_ON(prev && addr <= prev->vm_start); > + VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end)); > + VM_WARN_ON(addr >= end); Maybe converting to VM_WARN_ON_ONCE() would be kinder.