From patchwork Wed Feb 19 01:44:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11390199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 823B41395 for ; Wed, 19 Feb 2020 01:44:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4B49824655 for ; Wed, 19 Feb 2020 01:44:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AeiF/BUI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B49824655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1E78F6B000D; Tue, 18 Feb 2020 20:44:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1C0416B000E; Tue, 18 Feb 2020 20:44:50 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B07E6B0010; Tue, 18 Feb 2020 20:44:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E8B9F6B000D for ; Tue, 18 Feb 2020 20:44:49 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8F2E0180AD81A for ; Wed, 19 Feb 2020 01:44:49 +0000 (UTC) X-FDA: 76505182698.02.birth73_6448f0e96f31f X-Spam-Summary: 2,0,0,c3297a5fa2e5e718,d41d8cd98f00b204,minchan.kim@gmail.com,:akpm@linux-foundation.org:linux-kernel@vger.kernel.org::linux-api@vger.kernel.org:oleksandr@redhat.com:surenb@google.com:timmurray@google.com:dancol@google.com:sspatil@google.com:sonnyrao@google.com:bgeffon@google.com:mhocko@suse.com:hannes@cmpxchg.org:shakeelb@google.com:joaodias@google.com:joel@joelfernandes.org:sj38.park@gmail.com:alexander.h.duyck@linux.intel.com:jannh@google.com:minchan@kernel.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3352:3865:3871:4250:4321:5007:6119:6261:6653:6742:7576:7903:10004:10226:11026:11658:11914:12043:12296:12297:12517:12519:12555:12679:12895:13069:13311:13357:13894:14096:14181:14384:14394:14721:21080:21444:21451:21627:21990:30054:30070,0,RBL:209.85.216.65:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5 ,Netchec X-HE-Tag: birth73_6448f0e96f31f X-Filterd-Recvd-Size: 4670 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Feb 2020 01:44:49 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id q39so1821202pjc.0 for ; Tue, 18 Feb 2020 17:44:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/6BKpu6I9GWZilmKCDR/xIEf9kb10U/fQ/hS1RFxo/E=; b=AeiF/BUIODJ7Elpdb3GXCCzXBoQS9IDbCw9VSMC/jL+pPhcr/hr375CchvyTPhz7Pw 0UOfnIko0AblDWL/yTdmeiTlRoIfhMWdWFD3hNHRiqveweEiIFdLmzsDjyssGqVlyrTi febRwSW0h0+kaMkhfKy6efdR7uMe5zL+d+KmyIKLPs0rgr5VxIwjrVpWWZEPFxsMwZ23 J/8duxiMxzzsojGZ4V6XQhchtynRJdtbiMasGQl4+ZCJDiom8Qude7YarbGY5V0fKzVt AFoKRAVeNBBiW7zrGGHfvJ2A02+p1VpXuF6g0cnYJV37hKbKe7v2cv28gZItVOFqnAa3 aTPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/6BKpu6I9GWZilmKCDR/xIEf9kb10U/fQ/hS1RFxo/E=; b=tfsp3hytop+JZ9HTHC84rQnBSyxY7mbb5BZr1+1kfxGHSr3rE4+MxAVAxSRWJW7Cfm d5yUwqDPWYrCLzfYu3te5nSJCK7kJg4oUuFbetM1e/LhRpk47H7i61PBNkn+S1tytpCJ go9I1U1ktz5dhDbWi6bdPTbLlpqYSbLGcRH3TyvOFXNG5p0O+RNXKv61Hiy56VXj5dnB Bm8cXeozPprCSx4jIdQb/373IgnDv+JHf/RpKkuxJUKlmwkKEN8+OH3cCz/Q+PsX7RvN AeoS0iDffhT09oFataNtRiOizqlQ6sa/1qMiwNkrZkZNk/Tl0zajhKxP88kHUqZAM5Gn ZCLw== X-Gm-Message-State: APjAAAVWgWFqwC5/3tw9EX67DAcNrh1eNaYRptb5hhDF5K27s29IdzGp RFXq3jivwZwMi/fQCLsKND0= X-Google-Smtp-Source: APXvYqwwKle6VVN2am3/CWIym5vOlHdjzCyQZW3QPgCSqnuGkU97ImrWpOZRQFtL2HjvnrD66h8CEw== X-Received: by 2002:a17:902:8f8e:: with SMTP id z14mr24068362plo.195.1582076688168; Tue, 18 Feb 2020 17:44:48 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id t186sm221192pgd.26.2020.02.18.17.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 17:44:46 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: LKML , linux-mm , linux-api@vger.kernel.org, oleksandr@redhat.com, Suren Baghdasaryan , Tim Murray , Daniel Colascione , Sandeep Patil , Sonny Rao , Brian Geffon , Michal Hocko , Johannes Weiner , Shakeel Butt , John Dias , Joel Fernandes , sj38.park@gmail.com, alexander.h.duyck@linux.intel.com, Jann Horn , Minchan Kim Subject: [PATCH v6 6/7] mm/madvise: employ mmget_still_valid for write lock Date: Tue, 18 Feb 2020 17:44:32 -0800 Message-Id: <20200219014433.88424-7-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200219014433.88424-1-minchan@kernel.org> References: <20200219014433.88424-1-minchan@kernel.org> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Oleksandr Natalenko Do the very same trick as we already do since 04f5866e41fb. KSM hints will require locking mmap_sem for write since they modify vm_flags, so for remote KSM hinting this additional check is needed. Signed-off-by: Oleksandr Natalenko Signed-off-by: Minchan Kim Reviewed-by: Suren Baghdasaryan --- mm/madvise.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index f6d9b9e66243..c55a18fe71f9 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1118,6 +1118,8 @@ int do_madvise(struct task_struct *target_task, struct mm_struct *mm, if (write) { if (down_write_killable(&mm->mmap_sem)) return -EINTR; + if (current->mm != mm && !mmget_still_valid(mm)) + goto skip_mm; } else { down_read(&mm->mmap_sem); } @@ -1169,6 +1171,7 @@ int do_madvise(struct task_struct *target_task, struct mm_struct *mm, } out: blk_finish_plug(&plug); +skip_mm: if (write) up_write(&mm->mmap_sem); else