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=-4.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 C3539C433E3 for ; Wed, 15 Jul 2020 18:37:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 80B5D20672 for ; Wed, 15 Jul 2020 18:37:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Y+TX0qRG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80B5D20672 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 023038D0003; Wed, 15 Jul 2020 14:37:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3CB46B000C; Wed, 15 Jul 2020 14:37:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2C748D0003; Wed, 15 Jul 2020 14:37:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id D91136B0008 for ; Wed, 15 Jul 2020 14:37:24 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8A7F02476 for ; Wed, 15 Jul 2020 18:37:24 +0000 (UTC) X-FDA: 77041168008.23.ink42_2a1092026efb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 8450B37621 for ; Wed, 15 Jul 2020 18:37:21 +0000 (UTC) X-HE-Tag: ink42_2a1092026efb X-Filterd-Recvd-Size: 10321 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jul 2020 18:37:21 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id h19so3692057ljg.13 for ; Wed, 15 Jul 2020 11:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9qQHm2b+3rwbBTzFM/lqzsH6S1Rv7/QR/QYGW+OhMFc=; b=Y+TX0qRGwQIRFrxBRRdvNjZH7UgARoC+KCS4tqoaotvEqXLNKmqCit9K/l4Ucq7pp+ rtr3PG3sTjcq17LFAFMOd5vvu7wFr8lWTBiOi3e6ZLG+md72Rn6kNWfTyDy7ujKoNK67 8XoVzr+fjQuVqWBY8h75boTmQ608nLGbj9cZ0= 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=9qQHm2b+3rwbBTzFM/lqzsH6S1Rv7/QR/QYGW+OhMFc=; b=BZ+428cLRigT/XPXaj7mlZoOdIdPDC4fGwpCFUX9iHqVh6Tfvo3v7+BvdH4HbERQa3 JJpbWn1J7VIMw8pCKwsbR8EtsZS+vpqUcqUy9po5nFIlE5fu38sIXBirXdRqdjNwTsF4 3DJsQnwDToFAV6wl6eEwrBgQhcWoIOHB5i6DEe01gj8XNaTmHwbnKbQRqBsBxCG3TnaK +rwlo4UeG1VnLiyUXmnl13JWLHZ59TcI0drKdPOBVqH/6rz7JkpLrj5UwsbUokGxPKKX IRta8DC5wZj74lOPDZn5wKaNqntLLlosgd3q50l0dnB3fU6YMhTNZdNbGnMOubkeN7kw XsXQ== X-Gm-Message-State: AOAM533LNjlDwm0LMckMDwL8XpLB6fEpBOuCAs089ps0y3li4Ts7XFtr pK+b2Nl0KJ+01wLqpX0FHFOLM7mJ9aQ= X-Google-Smtp-Source: ABdhPJx5brRFvsZR7x7qZzLkUPa6qLJuZFSde9TSQq3wd+TtewzxSMPJLE0URPT15ELuCFQmKhkVhw== X-Received: by 2002:a2e:9b06:: with SMTP id u6mr213142lji.24.1594838239124; Wed, 15 Jul 2020 11:37:19 -0700 (PDT) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com. [209.85.167.50]) by smtp.gmail.com with ESMTPSA id y188sm785380lfc.36.2020.07.15.11.37.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Jul 2020 11:37:17 -0700 (PDT) Received: by mail-lf1-f50.google.com with SMTP id c11so1617830lfh.8 for ; Wed, 15 Jul 2020 11:37:16 -0700 (PDT) X-Received: by 2002:a05:6512:3f1:: with SMTP id n17mr178224lfq.125.1594838236066; Wed, 15 Jul 2020 11:37:16 -0700 (PDT) MIME-Version: 1.0 References: <20200715135011.42743-1-kirill.shutemov@linux.intel.com> In-Reply-To: <20200715135011.42743-1-kirill.shutemov@linux.intel.com> From: Linus Torvalds Date: Wed, 15 Jul 2020 11:36:59 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCHv2] mm: Fix warning in move_normal_pmd() To: "Kirill A. Shutemov" Cc: Andrew Morton , Linux-MM , Linux Kernel Mailing List , Naresh Kamboju , Joel Fernandes , William Kucharski Content-Type: multipart/mixed; boundary="00000000000089243c05aa7f3607" X-Rspamd-Queue-Id: 8450B37621 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: --00000000000089243c05aa7f3607 Content-Type: text/plain; charset="UTF-8" On Wed, Jul 15, 2020 at 6:50 AM Kirill A. Shutemov wrote: > > mremap(2) does not allow source and destination regions to overlap, but > shift_arg_pages() calls move_page_tables() directly and in this case the > source and destination overlap often. It Actually, before we do this patch (which I think is a good idea), I'd like Naresh to test the attached patch. And Kirill, Joel, mind looking it over too. IT IS ENTIRELY UNTESTED. But I hope the concept (and the code) is fairly obvious: it makes move_page_tables() try to align the range to be moved, if possible. That *should* actually remove the warning that Naresh sees, for the simple reason that now the PMD moving case will *always* trigger when the stack movement is PMD-aligned, and you never see the "first do a few small pages, then do the PMD optimization" case. And that should mean that we don't ever hit the "oh, we already have a target pmd" thing, because the "move the whole pmd" case will clear the ones it has already taken care of, and you never have that "oh, there's an empty pmd where the pages were moved away one by one". And that means that for this case, it's _ok_ to overlap (as long as we copy downwards). What do you think? Ok, so I could easily have screwed up the patch, even if it's conceptually fairly simple. The details are small, but they needed some care. The thing _looks_ fine to me, both on a source level and when looking at the generated code, and I made sure to try to use a lot of small helper functions and couple of helper macros to make each individual piece look clear and obvious. But obviously a single "Oh, that test is the wrong way around", or a missing mask inversion, or whatever, could completely break the code. So no guarantees, but it looks fairly straightforward to me. Naresh - this patch does *NOT* make sense to test together with Kirill's (or Joel's) patch that says "don't do the PMD optimization at all for overlapping cases". Those patches will hide the issue, and make the new code only work for mremap(), not for the initial stack setup that caused the original warning. Joel - I think this patch makes sense _regardless_ of the special execve() usage case, in that it extends your "let's just copy things at a whole PMD level" logic to even the case where the beginning wasn't PMD-aligned (or the length wasn't sufficient). Obviously it only triggers when the source and destination are mutually aligned, and if there are no other vma's around those first/last PMD entries. Which might mean that it almost never triggers in practice, but looking at the generated code, it sure looks like it's cheap enough to test. Didn't you have some test-cases for your pmd optimized movement cases, at least for timing? Linus --00000000000089243c05aa7f3607 Content-Type: application/octet-stream; name=patch Content-Disposition: attachment; filename=patch Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kcnphvie0 IG1tL21yZW1hcC5jIHwgNjcgKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysr KysrKysrKysrKysrKysrKysrKysrKwogMSBmaWxlIGNoYW5nZWQsIDY3IGluc2VydGlvbnMoKykK CmRpZmYgLS1naXQgYS9tbS9tcmVtYXAuYyBiL21tL21yZW1hcC5jCmluZGV4IDZiMTUzZGMwNWZl NC4uMzEyNTQyM2M4MzlhIDEwMDY0NAotLS0gYS9tbS9tcmVtYXAuYworKysgYi9tbS9tcmVtYXAu YwpAQCAtMjU0LDYgKzI1NCw3MSBAQCBzdGF0aWMgYm9vbCBtb3ZlX25vcm1hbF9wbWQoc3RydWN0 IHZtX2FyZWFfc3RydWN0ICp2bWEsIHVuc2lnbmVkIGxvbmcgb2xkX2FkZHIsCiAKIAlyZXR1cm4g dHJ1ZTsKIH0KKworI2RlZmluZSBBRERSX0JFRk9SRV9QUkVWKGFkZHIsIHZtYSkgXAorCSgodm1h KS0+dm1fcHJldiAmJiAoYWRkcikgPCAodm1hKS0+dm1fcHJldi0+dm1fZW5kKQorCitzdGF0aWMg aW5saW5lIHZvaWQgdHJ5X3RvX2FsaWduX3N0YXJ0KHVuc2lnbmVkIGxvbmcgKmxlbiwKKwlzdHJ1 Y3Qgdm1fYXJlYV9zdHJ1Y3QgKm9sZCwgdW5zaWduZWQgbG9uZyAqb2xkX2FkZHIsCisJc3RydWN0 IHZtX2FyZWFfc3RydWN0ICpuZXcsIHVuc2lnbmVkIGxvbmcgKm5ld19hZGRyKQoreworCWlmIChB RERSX0JFRk9SRV9QUkVWKCpvbGRfYWRkciAmIFBNRF9NQVNLLCBvbGQpKQorCQlyZXR1cm47CisK KwlpZiAoQUREUl9CRUZPUkVfUFJFVigqbmV3X2FkZHIgJiBQTURfTUFTSywgbmV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