From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E03AC3F2CD for ; Fri, 28 Feb 2020 23:20:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 439F2246B5 for ; Fri, 28 Feb 2020 23:20:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="p712VrGq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 439F2246B5 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 859726B0005; Fri, 28 Feb 2020 18:20:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E5686B0006; Fri, 28 Feb 2020 18:20:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D3256B0007; Fri, 28 Feb 2020 18:20:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id 521B96B0005 for ; Fri, 28 Feb 2020 18:20:08 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0E6632C7C for ; Fri, 28 Feb 2020 23:20:08 +0000 (UTC) X-FDA: 76541106096.30.cave84_124f83f8b120 X-HE-Tag: cave84_124f83f8b120 X-Filterd-Recvd-Size: 4663 Received: from mail-ua1-f65.google.com (mail-ua1-f65.google.com [209.85.222.65]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 28 Feb 2020 23:20:07 +0000 (UTC) Received: by mail-ua1-f65.google.com with SMTP id w15so1623161uap.0 for ; Fri, 28 Feb 2020 15:20:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VU34bwckjyg5xsCO6OcehkGprELR+hgQrM6MHlc+k24=; b=p712VrGqlJPpzao7YD3m5WX0LwQXtasWycAZR6Qv7IV0othNqCEH71tVJM2dopv6af sSO8BQuwI9/or54uFHbjxF2CZdx+mBayfoBqjtGedEVeI+as7B6KM8lW8g0A2yYN3KPf Bt5nJiuIcPY6xqYfFiU1su+u2LEuGh6MVdzDcI9oEmRy3zU0uimpQkB2C6GNcZp1ThKW ftlwSgDHO7rZaaPNKsUOMofgpJYnyN2NrPVF2PrRfd/HdlhYG0NSDq+3O5nSutE6lrIM 0nrGXHCVT0QfVmQkePA2n2I4pNWldsh6VIbF1ZbvzPNJCW5aIIzLigynVqrzxFeuH8Qc G/EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VU34bwckjyg5xsCO6OcehkGprELR+hgQrM6MHlc+k24=; b=k3n0Sj5BJcE+tuurNbCpx2P1AOCw5V2Oc2/Cdba7inhEO1SExgMPL5UjdVQRXbpD3Y 3Gpxzw+Jvnxl3btcj/IlS/jfsIM8/rQ9fwa8O5eLt/6+N647ECKRFY6EGae7IwXEwI4x H3sewmZ4P0zOCPpq8YHzyzDnXCDPwHspwESdx6JS3gie/Wn04IvAh1IdC/TNqzAYkgTe ANKxmVRAudhy5ACR2lzVhb5orMENMtJR9PNkxB63XCZlG/txz6U9XafX8YsxWX6tqkqi 2uorQ4n3TVWtDaYTgpO4gerA45+7P/ZQ209bNaPQ1V6C2HUg301i9E9Vol0U2lpjLHuA G1pw== X-Gm-Message-State: ANhLgQ0yBIve4iBhD9mStDiqVq3Y7Y8cy4J5UaVUYCClj/pkBYkZRBUd egOkF9kOeJqBNUqxllO5wKou+PzxxCYk/Bnz2EC48w== X-Google-Smtp-Source: ADFU+vu77RknxSN0Qez7GxUaCFdomtgxWWwgBofJYgMiqzYUzWYSNhzh9gQeVE9ot63IVGGE/yy38i9GzlZhRohTM4M= X-Received: by 2002:ab0:32cf:: with SMTP id f15mr3393489uao.42.1582932006884; Fri, 28 Feb 2020 15:20:06 -0800 (PST) MIME-Version: 1.0 References: <20200219014433.88424-1-minchan@kernel.org> <20200219014433.88424-7-minchan@kernel.org> In-Reply-To: <20200219014433.88424-7-minchan@kernel.org> From: Suren Baghdasaryan Date: Fri, 28 Feb 2020 15:19:55 -0800 Message-ID: Subject: Re: [PATCH v6 6/7] mm/madvise: employ mmget_still_valid for write lock To: Minchan Kim Cc: Andrew Morton , LKML , linux-mm , linux-api@vger.kernel.org, oleksandr@redhat.com, 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 Content-Type: text/plain; charset="UTF-8" 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: On Tue, Feb 18, 2020 at 5:44 PM Minchan Kim wrote: > > 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 > --- > 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)) mmget_still_valid() seems pretty light-weight, so why not just use that without checking that the mm belongs to the current process first? > + 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 > -- > 2.25.0.265.gbab2e86ba0-goog >