Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3476001pxb; Sun, 26 Sep 2021 16:45:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUTpqq57lZ2F0v75x9zvJSqzDSPhFYSKyfBPjoztEixJrEmcjzUvPCV8LZftkiajI3flD7 X-Received: by 2002:a17:906:a294:: with SMTP id i20mr3138917ejz.128.1632699954554; Sun, 26 Sep 2021 16:45:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632699954; cv=none; d=google.com; s=arc-20160816; b=J+x/BXuuutYQIAX5Vt7qMUAfSxvmJ+Aqjov7nx6bhjF2m0o012QzS05u6k79D0PVwW 1nuCZaggqjgpX38gT8LYl9CGah0HJCgto2TSuh7fwriKfpiFvCNvOJbtPOLKAaWjzfiw 5/QOV+ivVrlzNxu/CMb5TEfo6rFWqBDBMhxRaJM2kJ88he1Hx/8B1oKb0WXlnvfvxE0h W8BW/WbVyUpJhvvlMGUZD/nBABP6i1Wo8UqQB0hRvGKniSCIkcaAb4KObcX2VKgRVXC5 LpkXk7k6gJ7/3+CnDk1N2+3CuL3qdbl5t20wIw78zGXuuLxQgNsIPKlaYf/Z7bbxEwVy RAFw== 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:date:subject:cc:to:from :dkim-signature; bh=NySU333JXW/fyiS9W1CxTkc8pnmhF1ZxQI/NACcKQmE=; b=pepnHM1nWXdKfpNZdcrEkx3H5v24uLyRnBsX5I0Zu28bbZ6tHXF68b16d/CmGhFCKB GiujOLjciS8C5j4Hqpmdgsed6Kk92+A3N0yY8ox1r3RvrzuNOn6auFBS6Hh+T0Q4kxdK gWtog3tFAittvhAM75unpcQW95Wle0j6Ru6i7kinDPmlFIZxKzJP4dbzW7ktJc8E+s12 LTcGKQ410LHv6zCUKVSXPegsZrjXEhhGb/cIoqNm33bqCNa475NkZAoeP9aFrKHc0Oux ePJRaZjqNy+tv8QNe8LRKB6VVz39r/g85HVbZaq5TeLFOLS7embhuCKVvTUdfr4tWRtU pm2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=S2Xi3H0D; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 6si21201205eje.339.2021.09.26.16.45.31; Sun, 26 Sep 2021 16:45:54 -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=@gmail.com header.s=20210112 header.b=S2Xi3H0D; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232316AbhIZXph (ORCPT + 99 others); Sun, 26 Sep 2021 19:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbhIZXpf (ORCPT ); Sun, 26 Sep 2021 19:45:35 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE1ECC061570 for ; Sun, 26 Sep 2021 16:43:58 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id w11so10475869plz.13 for ; Sun, 26 Sep 2021 16:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NySU333JXW/fyiS9W1CxTkc8pnmhF1ZxQI/NACcKQmE=; b=S2Xi3H0DaUdTWODZoF6hKlWXPNbgIRsxr+vIrSIhNnJVNSOFJz/CL1weP2sL5o/aC8 paGG1RCdehDqjnIGdEuBezmF2cfX5r7V75kFFEx7yR73kkvUzjUDdqBrf9BrrJiKM7cC pmHlhh1Gf4IALFaw9lBJKJyZGODDCdcbHsiGf02WdaRxzCVPDs9+25P5/bKOhiBdBLyd mh9KXGUJt/7fOUwc5kdkLGLTnwnpf1a7p8cEQv4wSc338zrdXcD2vj/04po7T4y1o7Su zyW4dnzYq4bN0B9fxef857ggnUOZiN+emo0zn3toHpLbDVvRFLCWrmqfGJq0VaK6THsq FuBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NySU333JXW/fyiS9W1CxTkc8pnmhF1ZxQI/NACcKQmE=; b=p1oa9LIt3j3GQiFYHmwLNJzQ+QBVwEDEu6o2y7wc2eU8UAOo3vzpXSWUQ9JbCxNZeN fsqOFAAOXDCr/ygaU7xJOcdTlB6e5nBrLTEpa2ebJSSEl82K+6j3QWmhy1vXBvHSlkm4 i9uFuoqYnfWBzCatALDS1uZG5D6sn2nYWQaUvsKFTBK9KDTPVRnpjBW7vDkXBpk/tYIP +61agflGvBFL0V/9QlBGvfE6tMSmvy9aMV1VqjSxOknxpvyST5jxq+H6luvfJJSg32p6 Lm1hk0RncpT4qm7cJVxZicBBoofAU26iIMvNcOtZSzBMA/ngjjVnpX3Ut0BNApnqtilk g6Rg== X-Gm-Message-State: AOAM533SdYj/xZKLteTFM68pNGzuOg7TBBc3HhbJlx9iJoYVaMhGkC/C 5MkwWbp7kq0xWNHH8t8xDts= X-Received: by 2002:a17:902:9684:b0:13e:32cb:c95d with SMTP id n4-20020a170902968400b0013e32cbc95dmr383828plp.31.1632699838216; Sun, 26 Sep 2021 16:43:58 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id n22sm16783686pgc.55.2021.09.26.16.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 16:43:57 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Peter Xu , Nadav Amit , Andrea Arcangeli , Minchan Kim , Colin Cross , Suren Baghdasarya , Mike Rapoport Subject: [RFC PATCH 3/8] mm/madvise: remove unnecessary checks on madvise_free_single_vma() Date: Sun, 26 Sep 2021 09:12:54 -0700 Message-Id: <20210926161259.238054-4-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210926161259.238054-1-namit@vmware.com> References: <20210926161259.238054-1-namit@vmware.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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; 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