Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2100511rwl; Sun, 26 Mar 2023 16:01:47 -0700 (PDT) X-Google-Smtp-Source: AKy350aTVvhgMtedgJsZm4xAaw33yUkYj8btty9hip2NbmXjepEMphPRahnYUDbxVF3rwD0PRtQT X-Received: by 2002:a17:907:a50d:b0:878:481c:c49b with SMTP id vr13-20020a170907a50d00b00878481cc49bmr12353249ejc.1.1679871707517; Sun, 26 Mar 2023 16:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679871707; cv=none; d=google.com; s=arc-20160816; b=jysvM7IOKzd8cXYPZC85U5HQz203S8+CHWReS6sM45EjYDlv+hhGIxhFtkCbpeOYUB i9nmdBD8xrWc01cy5My4oU3giVn03hJmHpmhjco2t9meX4Nqrc1fQDHnr99n6o8QI692 XXs+Z2huIt3QyhM+DD6ebxAP88omSwvy8BX8BEc0PK8eKto7eV7VABF8ZkmA/zlE/g0F ScClXxCtArI3ELlt5k56Qh0ddkkkwJieFZDeErNt7gxGZDPmGqP4a7kr2LpYoc3r8AQj DPnmUpGmGJjeg0IwOo2QGU5TQGT5adSuMhZElzX+FOuBvHatWMVdVIxuQ4ewFKW09zZ6 Wm3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9fZkdxeeHkFCzAR8aqy81oHdx9YlDO1HnuZfhrn/TQ8=; b=nGS/bNutAeUjzgN09bUG9xJiPywsaKJ6NQWSfxggEqWcu/HsAofEaecpgrkqTZFto3 PMi16O6QcyO20AOjWd1OAaUdkzMu+HEHvKxRTzxEsXlKLo5SJJroMYgMxjyzFTmeuAXP 9A5GvuY3PTX6EILmjPQWN0Z77rkDh1EwDZSRKTXIWrZTSm0dJALKbt2D/gUXTLN5f7kw eCnD6A3uXvhQ4GvlVxTXGKw3ku43B3mI4odY5lhUVQr8wyyvfvAKybXfTjJeeW9jZcgg BOMmUfx7YBXQNkzGJojyuQuocBWuVtxzzpFKXC6seRFFJRP/NhV945pLKQ+SnOPuRd83 xNJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="eSv/r4S8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds22-20020a170907725600b0093defbd6283si9950361ejc.1034.2023.03.26.16.01.01; Sun, 26 Mar 2023 16:01:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="eSv/r4S8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229596AbjCZWs2 (ORCPT + 99 others); Sun, 26 Mar 2023 18:48:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbjCZWs1 (ORCPT ); Sun, 26 Mar 2023 18:48:27 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 976FE4236 for ; Sun, 26 Mar 2023 15:48:25 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id cn12so28735754edb.4 for ; Sun, 26 Mar 2023 15:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1679870903; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9fZkdxeeHkFCzAR8aqy81oHdx9YlDO1HnuZfhrn/TQ8=; b=eSv/r4S8HeF5JxW79ORKgU8fYq/vw/bKT+NR9Y79aZYWhgWtjPO9M1jZEUmvpDyp+e gBboqx3KXWTg7FNdY7YNr/4vgkMTPadAOXje14caUSXNzIe5x7ISDbWZh5W+cqe7bkpi 6ytZ6z0e4qmBbDyEWapGtnPeLP6pPgCYYj/wY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679870903; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9fZkdxeeHkFCzAR8aqy81oHdx9YlDO1HnuZfhrn/TQ8=; b=hIoe4TYsfc7rhi8qdVIJLCaz8bGoURQEDLKDnszDYF2tD1ttt/MP0taUCXncxJM+ze FMX35Pr6qa8eXfDIy9KOXnSo3VcHFC8c3FJ7re976tpDuI8yecf15odqu+BDiqJn0WDO cHo7xNjCILVxjLPcQGx1tED1tcCfxeiKle0jLf/s7Wahy6qMnT+J3y4uF3wUnfzAqhJn DYN6aJ7Xwx9givRVABVZcPCiCk+YnfSUdg7mcDdKr4qK/ya5bMA89zqUAI93CCynodyw yzBXmddKUUusbpZBJ7QA19lUrWf3KKGPIWxEmrMuFQn49FXoNmTpKWjUGHGHaY8w6VOd Oc5A== X-Gm-Message-State: AAQBX9cP+kmEgUVicJYOYm5uq7uHaPIFvL1dXfT7PVtiFXAB69OZ+TEo zgWarfLbaq5H0hqPkrYMUXbCuwQt7fFRXx9d76QsbQ== X-Received: by 2002:a17:906:a04a:b0:91f:5845:4e3c with SMTP id bg10-20020a170906a04a00b0091f58454e3cmr10779637ejb.42.1679870903590; Sun, 26 Mar 2023 15:48:23 -0700 (PDT) Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com. [209.85.208.45]) by smtp.gmail.com with ESMTPSA id la18-20020a170907781200b00914001c91fcsm13398242ejc.86.2023.03.26.15.48.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Mar 2023 15:48:22 -0700 (PDT) Received: by mail-ed1-f45.google.com with SMTP id y4so28776680edo.2 for ; Sun, 26 Mar 2023 15:48:22 -0700 (PDT) X-Received: by 2002:a17:907:7b8a:b0:931:6e39:3d0b with SMTP id ne10-20020a1709077b8a00b009316e393d0bmr4811641ejc.15.1679870902220; Sun, 26 Mar 2023 15:48:22 -0700 (PDT) MIME-Version: 1.0 References: <20230324130530.xsmqcxapy4j2aaik@box.shutemov.name> <20230325163323.GA3088525@google.com> <20230326022658.GB3142556@google.com> In-Reply-To: <20230326022658.GB3142556@google.com> From: Linus Torvalds Date: Sun, 26 Mar 2023 15:48:05 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: WARN_ON in move_normal_pmd To: Joel Fernandes Cc: "Kirill A. Shutemov" , Michal Hocko , Naresh Kamboju , Andrew Morton , linux-mm@kvack.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 25, 2023 at 7:27=E2=80=AFPM Joel Fernandes wrote: > > So for that very reason, we still have to handle the bad case where the > source PMD was not deleted right? Well, so our rules are that if nothing is mapped in a particular page table directory (any level), then it must be empty. And that "must" is actually a hard requirement, because our exit path won't even spend time tearing down page tables that don't have any mappings in them. So if you were to have non-empty pmd entries that don't have a vma associated with them, there would be a memory leak, and we really would want to warn about that case. End result: it should be sufficient to do something like "if you don't have a mapping below you within this PMD, you can expand the movement down to a full PMD". And same with the above case. Of course, the more I think about this, the more I wonder "is this even worth it". Because we have (a) mremap() that can't trigger the problematic case currently (because not overlapping), and *probably* almost never would trigger the optimization of widening the move in practice. (b) setup_arg_pages() will probably almost never triggers the problematic case in practice, since you'd have to shift the pages by *just* the right amount so in the end, maybe the "real fix" is to just say "none of this matters, let's just remove the warning". An alternative "real fix" might even be to just say "just don't shift the stack by exactly a PMD". It's unlikely to happen anyway, it's not worth optimizing for, so just make sure it doesn't happen. IOW, another alternative could be something like this: --- a/fs/exec.c +++ b/fs/exec.c @@ -783,7 +783,14 @@ int setup_arg_pages(struct linux_binprm *bprm, unlikely(vma->vm_end - vma->vm_start >=3D stack_top - mmap_min_= addr)) return -ENOMEM; + /* + * Shift the stack up, but avoid shifting by + * exactly a PMD size, which causes issues + * when mixing page-sized and pmd-sized moves. + */ stack_shift =3D vma->vm_end - stack_top; + if (stack_shift && !(stack_shift & ~PMD_MASK)) + stack_shift -=3D PAGE_SIZE; bprm->p -=3D stack_shift; mm->arg_start =3D bprm->p; which is *really* quite ugly, and only handles the stack-grows-down case, and I'm not proud of it, and the above is also entirely untested. I will delete that patch from my system after sending out this email, and disavow any knowledge of that horrendously ugly hack. But if somebody else takes ownership of it and I won't be blamed for it, I would probably accept it as a solution. Shudder. That's nasty. Linus