From patchwork Sun Sep 26 16:12:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12518941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BAFDC433EF for ; Sun, 26 Sep 2021 23:44:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 95BF2610CA for ; Sun, 26 Sep 2021 23:44:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 95BF2610CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id EDD116B0078; Sun, 26 Sep 2021 19:43:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEB12900002; Sun, 26 Sep 2021 19:43:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B79CB6B007D; Sun, 26 Sep 2021 19:43:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id A27BE6B0078 for ; Sun, 26 Sep 2021 19:43:59 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6073B8249980 for ; Sun, 26 Sep 2021 23:43:59 +0000 (UTC) X-FDA: 78631354998.28.4FC97E3 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf04.hostedemail.com (Postfix) with ESMTP id 20B7150000AD for ; Sun, 26 Sep 2021 23:43:59 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id n2so10481713plk.12 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=ZWz807We9HgyH6S0e5NHEc0doDW1o47tRq+CmCOzpt7sH9EmPVNZ1lZ1/i+6kmcFIN P2mJFw9Ab1efg65zuCNSnyqRDpY6tqXomgzA+j5DdGWj0uDmO/lzidQ0NCh0hehRAYop jRrhPxkzb/weaPfj7e6VAeDCeBmSdI1Tx/Xzm29C4RXwFp2g5GTunzjRiFcXmxNrGu+X Koo9x+JaUWzAbMu4Cr27cCnS7nh1Eh+urV61NgnSfTJbKoWBd7THYqN75KvMk7BCblRI +JyHwJR+4M4K8MwVPt2Ho5bncq5Sbv4IHnKmcJnhfT+ZDgXigIwdZUKvMFceK326Ufqy YseQ== X-Gm-Message-State: AOAM530/h6wh1+Tf40RCtPCxwcZ0deIMYva3yFgbaQcsp2FBAl0bTpa9 tFNseZHIsNRmz9zq34MrqSI= X-Google-Smtp-Source: ABdhPJylHV5/+/gjFjZAYFu4kVShQNgLaLHnT25MFpUQmwpdWFzGophkZ/jj2j+GSp2ZtFbgIvdljg== 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 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 20B7150000AD X-Stat-Signature: swt7yau3p1j5zharnmza9i65of4kz5ep Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=S2Xi3H0D; spf=none (imf04.hostedemail.com: domain of mail-pl1-f174.google.com has no SPF policy when checking 209.85.214.174) smtp.helo=mail-pl1-f174.google.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1632699839-691690 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);