Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22564665rwd; Fri, 30 Jun 2023 09:31:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlFxaUrBM9eXeFabJUdft72DR5lYQ5mQUwqOjR0DeGeV0YZILtg0f79Os66KUZkAQ8HaSqaC X-Received: by 2002:a05:6a00:23c4:b0:67a:8f2a:2cb2 with SMTP id g4-20020a056a0023c400b0067a8f2a2cb2mr3651247pfc.20.1688142681528; Fri, 30 Jun 2023 09:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688142681; cv=none; d=google.com; s=arc-20160816; b=ZsNHGkt0DrIp+3fmEcflnnwIcZqwx1EF0jMXM/CgJpVsXiGcIxKFxHv29hEgmNorV8 O8QESXINrAAc/5azcpnlscaY8gjTUp1pe87taj6AUXtv6hAWig50ZCxvxVdPZusbz8Kz HRE0pnyHeNySswFIvgWNp6PwXJnvOFJ2Y8y3+1xon+oiFz9ZUAv7LPKeCgHiocoEieXp xuwedRtDiz2wcnUxnARm4wYBEyw1RQiN7HMDob5aY6BSp5QaiId8Ef537FXf2yfF/tAN lfFEm5Gq9cwaOWxGb+CNf8W0deeoL6cJr0ovNapfAOmUDN0MRaAkOkOt5HNpdDVYRXB3 PxiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=j3I7zANFd6QAuWoZlCVaHAW7HE1PeX5cogAMvb+4P44=; fh=KmIbSq8AlAjg08+Wm/hJgYw9vobRtHLGKRWpW8Ow+c0=; b=S8rPeNBPHMRDNQusG+Pg9W6AG/Q2v8rOkl4JlDBvqUqELV/RfHnqbN4I5PNdaUyeYW 45C2tFmbjYcwy7YDefCGoAHLDP1wY07oVpHCVuZkhgwNBL9YiixtwmGtUS/6B5E14zVj TDomgjEYbMl65D1n63TnQSgNm4XCZapPxggTQMOUf7F3kIVWYM6Zp6WH+p+965ATyHUr iM3wG6HBJ/gSbk4l/UEVLZwFwVkJonk+3W6vp4D1haER1vYAkPN00Az4HqB91JTS9x5k Ug8wisA6KD/K7SvWn/64CN31f47B3mB1SfDT1jEymVyUX0ZxyDfWcfGv3sPyBd0rXSpQ Rr/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="GrJQAo/9"; 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 q17-20020a056a00089100b00666887b7eecsi7960940pfj.312.2023.06.30.09.31.08; Fri, 30 Jun 2023 09:31:21 -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="GrJQAo/9"; 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 S232185AbjF3QT4 (ORCPT + 99 others); Fri, 30 Jun 2023 12:19:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232897AbjF3QTv (ORCPT ); Fri, 30 Jun 2023 12:19:51 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E2723C06 for ; Fri, 30 Jun 2023 09:19:50 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2b69ff54321so33349221fa.2 for ; Fri, 30 Jun 2023 09:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1688141988; x=1690733988; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=j3I7zANFd6QAuWoZlCVaHAW7HE1PeX5cogAMvb+4P44=; b=GrJQAo/99ujxjtCM9Fh85YRwlV1iYIFAmoj36GFuJhWYbEHO6kt62yYldyzOplG+A7 dgUFTFrKwfPsDGKGHZpAZ56sfXF1+WAICLcuQ+b4bXOg2MMP9Yps/1ZcET1dqppLaKUw 16ek9zvj1YHAcMVJangXNUpiystZ/wz8Fj5Yc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688141988; x=1690733988; h=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=j3I7zANFd6QAuWoZlCVaHAW7HE1PeX5cogAMvb+4P44=; b=Riwzr7XjuveJdYSSiLpYzQZ/E6rwMf/hPrzmBkf8kLBwjYGhafdQZ264fRkQGLt1rP XoNjbSJPzlD1LWu/s4CSsCG82elb9AgRqIMlXtnif/pHkitNpcTVFALKj1xDGsZY2IDb WX7hOTb1N132iWCh/1jKN/4RdyuvDOPSldvyJ1HrmvnsCG4xni9EJdGTjtlJLl65nUQV I92LRmWOniITH3HtYLV+YE6I+WpQENR+JN0S9iyXwTLtuI7kEuSNQeq7TIoHQZN2iGDQ fTK36m2znT/RjN5De6/XL6Tuik8jpSctGRE3FUkqEhvxPsemXt4B4FG0GMnowlmEy4Cz ceNg== X-Gm-Message-State: ABy/qLaDSvF0Vg3L/cuEBKPs4WNgkUtzvn9GRid9O6fmwaFMz3O3SO9P e6hnc7hJcZMeJoWPvxawI50iX5Pv5Fd4MYJmQsBLrsJh X-Received: by 2002:a2e:86c3:0:b0:2b6:a65f:729d with SMTP id n3-20020a2e86c3000000b002b6a65f729dmr2352292ljj.13.1688141988257; Fri, 30 Jun 2023 09:19:48 -0700 (PDT) Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com. [209.85.167.45]) by smtp.gmail.com with ESMTPSA id t26-20020a2e781a000000b002b6cde9f325sm537085ljc.105.2023.06.30.09.19.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Jun 2023 09:19:47 -0700 (PDT) Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-4fba86f069bso169463e87.3 for ; Fri, 30 Jun 2023 09:19:47 -0700 (PDT) X-Received: by 2002:a05:6512:3994:b0:4f9:58bd:9e5a with SMTP id j20-20020a056512399400b004f958bd9e5amr2835506lfu.27.1688141987079; Fri, 30 Jun 2023 09:19:47 -0700 (PDT) MIME-Version: 1.0 References: <20230630160519.3869505-1-Liam.Howlett@oracle.com> In-Reply-To: <20230630160519.3869505-1-Liam.Howlett@oracle.com> From: Linus Torvalds Date: Fri, 30 Jun 2023 09:19:29 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] mm: Update do_vmi_align_munmap() return semantics To: "Liam R. Howlett" Cc: Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 Fri, 30 Jun 2023 at 09:06, Liam R. Howlett wrote: > > Update do_vmi_align_munmap() to return 0 for success. Clean up the > callers and comments to always expect the lock downgrade to be honored > on the success path. The error path will always leave the lock > untouched. Thanks for doing this, but with this cleanup, it becomes clear that some of the callers that asked for a downgrade didn't actually want that at all... For example: > + if (do_vma_munmap(&vmi, brkvma, newbrk, oldbrk, &uf, true)) > + goto out; > + > + mmap_read_unlock(mm); > + goto success_unlocked; this clearly wanted the lock to be dropped entirely. As did this one: > ret = do_vmi_munmap(&vmi, mm, start, len, &uf, downgrade); > /* > - * Returning 1 indicates mmap_lock is downgraded. > - * But 1 is not legal return value of vm_munmap() and munmap(), reset > - * it to 0 before return. > + * Returning 0 is successful, but the lock status depends what was > + * passed in. > */ > - if (ret == 1) { > + if (!ret && downgrade) > mmap_read_unlock(mm); > - ret = 0; > - } else > + else > mmap_write_unlock(mm); And this one: > + ret = do_vmi_munmap(&vmi, mm, addr + new_len, old_len - new_len, > + &uf_unmap, true); > + if (ret) > + goto out; > + > + mmap_read_unlock(current->mm); I didn't look at what all the indirect callers here were doing, but it really looked to me like *most* callers wanted the lock dropped entirely at the end. In fact, looking at that patch, it looks like *all* of the callers that asked for downgrading actually really wanted the lock dropped entirely. But I may well be missing some context. So take this not as a NAK, but as a "you looked at all this code, could it perhaps be simplified a bit more still?" Linus