From patchwork Fri Jul 30 08:03:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12410621 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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 D20A3C4338F for ; Fri, 30 Jul 2021 08:03:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 64B0660F5C for ; Fri, 30 Jul 2021 08:03:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 64B0660F5C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0432F8D0002; Fri, 30 Jul 2021 04:03:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F353B8D0001; Fri, 30 Jul 2021 04:03:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4BA78D0002; Fri, 30 Jul 2021 04:03:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id CAB7D8D0001 for ; Fri, 30 Jul 2021 04:03:20 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6ECA82030C for ; Fri, 30 Jul 2021 08:03:20 +0000 (UTC) X-FDA: 78418514160.30.9147945 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf13.hostedemail.com (Postfix) with ESMTP id 298D11016C51 for ; Fri, 30 Jul 2021 08:03:20 +0000 (UTC) Received: by mail-qk1-f170.google.com with SMTP id k7so8616831qki.11 for ; Fri, 30 Jul 2021 01:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=MGzbYcDH1nDg768HY0nxSbDVEpHf6CaY6eKAkj1Bcno=; b=o9CkvmfR1TcmeOk6LOKvzvte8hfyZYPrZSw2A7Wzr6ScvLcANBE/Yoki51+w9yX2f6 LVZpGnEbwEkqt7Hnt4+bRy/6x7vHr//wG299GJtb3ki0DosAuUEDfoNE2XtI+uUhKWo8 JHPPLfpx8KtKArXuCe/nuOYN+WbhwkFd6C/is1BOTenZhPT2ltWUzirXBxTvUZUS+Eth QpoRVlzDTTDqPnJEkTWpSHqLZy5XfvU0CnPupILljD14KkG6MGijbWyMZkjws6psWPKu It373FYdIqlePn1A4XbdCWvefbcGFvZ9tg5krXyxfwhlI9Zg4rXj4U19/DZ057wpLO/T RdPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=MGzbYcDH1nDg768HY0nxSbDVEpHf6CaY6eKAkj1Bcno=; b=QE/S7113AgRcjixfVlcJu4JzADzxlO4Qd8MEeooqTiUr4zLvjJfaSS7T4qFAVB9xZv OBVt/r6ZxgzQeP7UbQsB/itxoHPskuvcV4xEfEBDNsidIGK9GlHYs/JtCPKdQ2lJBYME k6aBlp4s7ST/hOB03vsejOcxcFIH6cJbNJYdKloUopO2zpb7Z7u9JnYbr4elVnzQoXQg 1I2akPnjc8+hBWYh1whHnsFK847PLlU58QN+kulf0iu1qtO5zu5FXPrtQPu12oehGkNt 0DYOiXFw1WJjAZ5sE2P36OlAOFyBILwgv6rU586p75uUnHXn6nD1UBpO7u3Qx3jZeNXI a3TA== X-Gm-Message-State: AOAM5313ua1wuhtRqbhLu/lIsI/zhdVMGsQ67VcNiB47JId9Rx8iiDGS 4ulkxWwKVCKvudkjgBBbdSofyw== X-Google-Smtp-Source: ABdhPJykYS4oamptTpmIT6dFsy8t5YJDFW4VgtJtNRS/my2z80sEMhOQ8L7GnOEOo0Fymj/Aya18fA== X-Received: by 2002:a37:4042:: with SMTP id n63mr1074442qka.425.1627632199330; Fri, 30 Jul 2021 01:03:19 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id y9sm316166qtw.51.2021.07.30.01.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jul 2021 01:03:18 -0700 (PDT) Date: Fri, 30 Jul 2021 01:03:15 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Christoph Hellwig , Matthew Wilcox , "Eric W. Biederman" , Alexey Gladkov , Chris Wilson , Matthew Auld , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 13/16] mm: bool user_shm_lock(loff_t size, struct ucounts *) In-Reply-To: <2862852d-badd-7486-3a8e-c5ea9666d6fb@google.com> Message-ID: References: <2862852d-badd-7486-3a8e-c5ea9666d6fb@google.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 298D11016C51 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=o9CkvmfR; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of hughd@google.com designates 209.85.222.170 as permitted sender) smtp.mailfrom=hughd@google.com X-Stat-Signature: agp5dnxfj1t5kq1376mkr9ikreezdeqz X-HE-Tag: 1627632200-857040 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: user_shm_lock()'s size_t size was big enough for SysV SHM locking, but not quite big enough for O_LARGEFILE on 32-bit: change to loff_t size. And while changing the prototype, let's use bool rather than int here. Signed-off-by: Hugh Dickins --- include/linux/mm.h | 4 ++-- mm/mlock.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 7ca22e6e694a..f1be2221512b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1713,8 +1713,8 @@ extern bool can_do_mlock(void); #else static inline bool can_do_mlock(void) { return false; } #endif -extern int user_shm_lock(size_t, struct ucounts *); -extern void user_shm_unlock(size_t, struct ucounts *); +extern bool user_shm_lock(loff_t size, struct ucounts *ucounts); +extern void user_shm_unlock(loff_t size, struct ucounts *ucounts); /* * Parameter block passed down to zap_pte_range in exceptional cases. diff --git a/mm/mlock.c b/mm/mlock.c index 16d2ee160d43..7df88fce0fc9 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -813,21 +813,21 @@ SYSCALL_DEFINE0(munlockall) } /* - * Objects with different lifetime than processes (SHM_LOCK and SHM_HUGETLB - * shm segments) get accounted against the user_struct instead. + * Objects with different lifetime than processes (SHM_LOCK and SHM_HUGETLB shm + * segments and F_MEM_LOCK tmpfs) get accounted to the user_namespace instead. */ static DEFINE_SPINLOCK(shmlock_user_lock); -int user_shm_lock(size_t size, struct ucounts *ucounts) +bool user_shm_lock(loff_t size, struct ucounts *ucounts) { unsigned long lock_limit, locked; long memlock; - int allowed = 0; + bool allowed = false; locked = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; lock_limit = rlimit(RLIMIT_MEMLOCK); if (lock_limit == RLIM_INFINITY) - allowed = 1; + allowed = true; lock_limit >>= PAGE_SHIFT; spin_lock(&shmlock_user_lock); memlock = inc_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked); @@ -840,13 +840,13 @@ int user_shm_lock(size_t size, struct ucounts *ucounts) dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, locked); goto out; } - allowed = 1; + allowed = true; out: spin_unlock(&shmlock_user_lock); return allowed; } -void user_shm_unlock(size_t size, struct ucounts *ucounts) +void user_shm_unlock(loff_t size, struct ucounts *ucounts) { spin_lock(&shmlock_user_lock); dec_rlimit_ucounts(ucounts, UCOUNT_RLIMIT_MEMLOCK, (size + PAGE_SIZE - 1) >> PAGE_SHIFT);