Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3783803pxb; Mon, 27 Sep 2021 02:26:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCxHNq9ivoZZhGhxI4off/9pfkG7f9kgM5NCJmoG4fD1leXlE6qFKq8dkxMHqVeN1wuSDL X-Received: by 2002:aa7:9a01:0:b0:444:d6b1:352d with SMTP id w1-20020aa79a01000000b00444d6b1352dmr22580337pfj.45.1632734765775; Mon, 27 Sep 2021 02:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632734765; cv=none; d=google.com; s=arc-20160816; b=JTzZl/wX8EtJsWbgWJ7h4EP8Zzf0bPW2JzXny0h4FEZf+tt4BEq2Jx1oZLhZQxeDWa wI3YQNxVZ9zx7Kgc+l/BzFH3hS825SvJzOUy/fJhrtYlIWd5/JD938aaiCRwlFlY/QYw EbULR83xHGnQDMVh6ExihotvH46dpKzT8/G0RKsSM1tyess0tvmQLRf0JI8x4+Y8giDZ amgYC+VbAiMFbXKpx8GqYURjchYSK5RlUslpxwPZqa2AGgED20w50mjR2hZKLTrYaCvQ DgS3AlBWd5HrAqRSJT3I5QUid0evSHRROUZ9WvSaF2NesAdFOVQxKUPUwRQJI9fH4kYd 0Djw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Tyy6Dv7V4fb/Ljhb18nEvTV2h/rNzPynwFMmcx94u8M=; b=d22MBL4E17J8uGpx44sFZcR99AqZWSUxVJwwpwOvE32hmVrqSVslCt3B3o+8IJrxYd rWF/B6moxzhcyW0dQ0P5aPk94l3buy7FuGjwPQGZH7jDr30rj1svxjw62iIEGOI/irbC RcF/T4QjuGHRV/wgANuR0TAJ20CmX1vDXUooEVqjnqkcCFZGdPrq/E085NaNzJ35CWiy 1dS2EvWCuOeV4UU6aTAfX+atUKvJpogJLZOHDykRiCODhy4nR+MLUF66tEdb6Yt2EwpV CHgIcolhNjmFSx43+/YexTeARjuLQIniZHovKHWK//XuATRMsdR5phnOmvva5yWorpg/ lPfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20210112.gappssmtp.com header.s=20210112 header.b=Px18PFMm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si21583630pgl.542.2021.09.27.02.25.53; Mon, 27 Sep 2021 02:26:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20210112.gappssmtp.com header.s=20210112 header.b=Px18PFMm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233680AbhI0J0N (ORCPT + 99 others); Mon, 27 Sep 2021 05:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233657AbhI0J0N (ORCPT ); Mon, 27 Sep 2021 05:26:13 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68886C061575 for ; Mon, 27 Sep 2021 02:24:35 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id u8so73622117lff.9 for ; Mon, 27 Sep 2021 02:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Tyy6Dv7V4fb/Ljhb18nEvTV2h/rNzPynwFMmcx94u8M=; b=Px18PFMmqv5tM0ES8a9DDmI150bGqOY2axThJnD9LQD345HFLscARXZ7aNBhhL6O9w OlBxtwbGSgDcaO1tiDwu4HCuvbedUfA5kRiqW9fCvubYCDFeF7rsQkeirLA6AB9lDB/+ 98D4prIrxs2zuHq+abJdHTtImN4MZ6SZcve32xEzHpT4+OdJq2l8OEAMiq83Zk87UMod klxZJpckzW1ev6CxHOj8DP4bmrRwNgWH8pm6RSylRwDUFPZ0tzQivrWecSDw+ffgv0fi DtnfuBWoG7JjfUuOBGdlE7kj2kcCELWQWqUxwX2lNaamIIYTGBkdCuSGw43dWJoeY49U rLTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Tyy6Dv7V4fb/Ljhb18nEvTV2h/rNzPynwFMmcx94u8M=; b=23fKEsD0B+uyYNy1ckEccQ8dLx5eyWgHaQNeuJtTqha2Q1qLfuKexEU6ywyWdRKl6Z qcQoouJf6oe3sw106s8Pqk2Ms1OZ2IdHkm44N5soqqwo3dhAFmNPAZjzPVyF/FmSTmv7 fCXxNU0ft39bDVkh194rXB4dFctpcqm0r/7ljQrSeyZYEVgrXQNYUr20jDHheQLW0+2l Xqebc+RMox/BvDr107jpwAAEWXxT32g17xk6yosI+vstr9kfZyHyWDqzA3T+ABkISKlT rRoY2iUqINoLkVVl9wVrUkVhOq76WE5Sw0BcgpF5kXgr8KKRW2lu4yxgpz80Kmrxy/4Z RGqQ== X-Gm-Message-State: AOAM530l42+NUmSa/QQ1B8vmW5NDIkheKKy5toKireJeZoc3Ra/yF9FG 9FZJcvUFtzqrm6bG425hzuDGag== X-Received: by 2002:a05:6512:3ee:: with SMTP id n14mr24062637lfq.589.1632734673773; Mon, 27 Sep 2021 02:24:33 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id u14sm1538020lfi.231.2021.09.27.02.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 02:24:33 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id B29CC10306C; Mon, 27 Sep 2021 12:24:32 +0300 (+03) Date: Mon, 27 Sep 2021 12:24:32 +0300 From: "Kirill A. Shutemov" To: Nadav Amit Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Peter Xu , Nadav Amit , Andrea Arcangeli , Minchan Kim , Colin Cross , Suren Baghdasarya , Mike Rapoport Subject: Re: [RFC PATCH 3/8] mm/madvise: remove unnecessary checks on madvise_free_single_vma() Message-ID: <20210927092432.qdshyj67lkiq2cbv@box.shutemov.name> References: <20210926161259.238054-1-namit@vmware.com> <20210926161259.238054-4-namit@vmware.com> <20210927091709.ksv2fjudjpqhnu3n@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210927091709.ksv2fjudjpqhnu3n@box.shutemov.name> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021 at 12:17:09PM +0300, Kirill A. Shutemov wrote: > On Sun, Sep 26, 2021 at 09:12:54AM -0700, Nadav Amit wrote: > > From: Nadav Amit > > > > madvise_free_single_vma() currently rechecks that the range fits within > > the VMA, adapts it accordingly, and returns -EINVAL if the range is > > entirely outside of the VMA. > > > > The error-code of -EINVAL is incorrect according to the man pages (as it > > should have been -ENOMEM), but anyhow the range that is provided to > > madvise_free_single_vma() should always be valid. It is set correctly in > > do_madvise() and then rechecked in madvise_dontneed_free() is the s/is/if/ > > mmap-lock is dropped. > > > > Remove this check. > > > > Cc: Andrea Arcangeli > > Cc: Andrew Morton > > Cc: Minchan Kim > > Cc: Colin Cross > > Cc: Suren Baghdasarya > > Cc: Mike Rapoport > > Signed-off-by: Nadav Amit > > --- > > mm/madvise.c | 8 +------- > > 1 file changed, 1 insertion(+), 7 deletions(-) > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > index fe843513a4e8..17e39c70704b 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -716,14 +716,8 @@ static int madvise_free_single_vma(struct vm_area_struct *vma, > > if (!vma_is_anonymous(vma)) > > return -EINVAL; > > > > - range.start = max(vma->vm_start, start_addr); > > - if (range.start >= vma->vm_end) > > - return -EINVAL; > > - range.end = min(vma->vm_end, end_addr); > > - if (range.end <= vma->vm_start) > > - return -EINVAL; > > How did you test this change? > > As far as I can see, you leave 'range' uninitialized, but used for > walk_page_range() and mmu_notifiers. > > NAK. Sorry. My bad. mmu_notifier_range_init will init the range even if mmu notifiers are disabled. > > > mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, > > - range.start, range.end); > > + start_addr, end_addr); > > > > lru_add_drain(); > > tlb_gather_mmu(&tlb, mm); > > -- > > 2.25.1 > > > > > > -- > Kirill A. Shutemov -- Kirill A. Shutemov