Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp159765pxb; Wed, 27 Oct 2021 00:03:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZIQohQTW9Ui3d8OHzokRjlB/K/osdItH5of1BBgVhJOMy1cSYV+8b0t+MEmpWgwDtxbmf X-Received: by 2002:a17:903:1110:b0:13f:d1d7:fb5f with SMTP id n16-20020a170903111000b0013fd1d7fb5fmr26892228plh.6.1635318198308; Wed, 27 Oct 2021 00:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635318198; cv=none; d=google.com; s=arc-20160816; b=Fayhj105pHf1N+BxAedEwcjZ/YJG+uqgUY4ZISyZuSddSXnWFfpoZ9b2Qw1HE5r8Cc O7deDRakHWNeLLVQThRJgwOmN+eicFf4Oyg8piGJktKHYUv2YgnmOJjMW82BkVwv6cDf 6SUbRjWxOMQChjwueFZWymxu5fZE/NkWvlwdC4z78i4UAmSnfUb/xUBtbe0FFwH/LvAv 095InUGlRO89g9es2snfWrWDcS1J+CiEtDOvfXmq2T3Ej41oSph5ziwggm0+/CUEr44W 2m2jYJdM77saKnL+pDvfcjg6Kj6zhJcOcpl3vl5giCnGHPLs2GnYcTibjHbF6VC5INUF fJLw== 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=65K7xPMB5++D+E7Bfsj7avhsV6qayGu5o858lBV5Elw=; b=T4fOz5k8ffiFWBHi5XG+iqQyKyGmGWfkd9PbQ34WMHcGqmPFax3OymRX5EcFWAzJL1 RQQxFQHqfv28uHUXuuW0+oSpDI5gBuGJamkluTFDhMraprmAA1NgrqQgBSkoev8o0V1T vhcMazmV237Q43foMTjzvetz4Q+8BZjyiFNCJipDB/KteyT62e8HPEf3rx3azU55onZj boh7EFUXp1ngSt5Ro1EtYNh5OH6SMpLSGODTl0J8Uxrl1WMcnBbErAR7bC4hvwcnKFNu Dr0Vgef83QaRvQmbWKeHk/CecLfQiCROYyHxLa0FSjmsv/J0o78PJNWcG5vDoYOCTgxt gCIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=UFCHSPeX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j5si3112245plr.377.2021.10.27.00.02.53; Wed, 27 Oct 2021 00:03:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=UFCHSPeX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231348AbhJZSY5 (ORCPT + 99 others); Tue, 26 Oct 2021 14:24:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236001AbhJZSY4 (ORCPT ); Tue, 26 Oct 2021 14:24:56 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA4FBC061745 for ; Tue, 26 Oct 2021 11:22:31 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id w23so327794lje.7 for ; Tue, 26 Oct 2021 11:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=65K7xPMB5++D+E7Bfsj7avhsV6qayGu5o858lBV5Elw=; b=UFCHSPeXcQuOwM5lLBzpQb7MmItFB4AO1roGO3y4q5yr/hBmA5lT1VpaEAmhdJ8z/+ VYkqEAMbuPAv1Cp8LsRycDDHtNvQeQFx8ipOaDHKl6uW/BQM+UY8gkxeKK1rD6gGr5b5 UAPtkFa0BJoq6WvAzcEI5zbTFwjaDAQ8x976/sWxF14aJK3ZMtLOU5YZnYmTm2KtHcma 4yfclS5UycC8vhPriGnuQqwzjvOB6HwPARWPA5QDSSGLIZFoGvvzuROAIiV0JbwyFpH2 9ePnPpndZLepd6EXRifaI8NVaGxubCB3QnHbqqrjvdu4maqR49+vJ1T4iBJe7KGvwG0v ZgHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=65K7xPMB5++D+E7Bfsj7avhsV6qayGu5o858lBV5Elw=; b=7WBj0pxLuwSS/8dMkTrSErcY3BL0lzJgBYPoJULWI4wKJGkJfpgGIHocz58GecdI8o O6VQYFUYAUxoFqX1ccpLCGngNXh9pHDguk+/O4XliVKc3E1c7/cGolsb1Ah7uWaygxHy KBI5FzvVhnJ0aZoQku26N1UPIxzz51+sz2TkdUKeNaMs3nFFIBBCKEY+DOzDG1A8vIe/ J88FtjXfO0QQ+MF5DQcGPgoHrWVqlfr+NIyMoUKaNQbBWr5hbQLerOzS8pJboKPLFJm+ YBPf2dP1fLqB+MTT24sIgebdmlT/HDVqa2lu340blgc7zsPVbpQNmSyMYoP+vnDeiHdg 1ClQ== X-Gm-Message-State: AOAM532E/ZtKaTxTV95UrkNkDsN0gz0248T8BCzgE/U32DIzgMgh0rtU ejT74rvQfmGAhTmah8XYZJ/3ViMn1t/vF9W1dt9Tkg== X-Received: by 2002:a2e:b794:: with SMTP id n20mr149553ljo.313.1635272550203; Tue, 26 Oct 2021 11:22:30 -0700 (PDT) MIME-Version: 1.0 References: <20211026173822.502506-1-pasha.tatashin@soleen.com> <20211026173822.502506-4-pasha.tatashin@soleen.com> <7b131cb1-68d8-6746-f9c1-2b01d4838869@nvidia.com> In-Reply-To: <7b131cb1-68d8-6746-f9c1-2b01d4838869@nvidia.com> From: Pasha Tatashin Date: Tue, 26 Oct 2021 14:21:53 -0400 Message-ID: Subject: Re: [RFC 3/8] mm: Avoid using set_page_count() in set_page_recounted() To: John Hubbard Cc: LKML , linux-mm , linux-m68k@lists.linux-m68k.org, Anshuman Khandual , Matthew Wilcox , Andrew Morton , william.kucharski@oracle.com, Mike Kravetz , Vlastimil Babka , Geert Uytterhoeven , schmitzmic@gmail.com, Steven Rostedt , Ingo Molnar , Johannes Weiner , Roman Gushchin , songmuchun@bytedance.com, weixugc@google.com, Greg Thelen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi John, Thank you for looking at this series. > > static inline void set_page_refcounted(struct page *page) > > { > > + int refcnt; > > + > > VM_BUG_ON_PAGE(PageTail(page), page); > > VM_BUG_ON_PAGE(page_ref_count(page), page); > > - set_page_count(page, 1); > > + refcnt = page_ref_inc_return(page); > > + VM_BUG_ON_PAGE(refcnt != 1, page); > I am acutely uncomfortable with this change, because it changes the > meaning and behavior of the function to something completely different, > while leaving the function name unchanged. Furthermore, in relies upon > debug assertions, rather than a return value (for example) to verify > that all is well. It must return the same thing, if it does not we have a bug in our kernel which may lead to memory corruptions and security holes. So today we have this: VM_BUG_ON_PAGE(page_ref_count(page), page); -> check ref_count is 0 < What if something modified here? Hmm..> set_page_count(page, 1); -> Yet we reset it to 1. With my proposed change: VM_BUG_ON_PAGE(page_ref_count(page), page); -> check ref_count is 0 refcnt = page_ref_inc_return(page); -> ref_count better be 1. VM_BUG_ON_PAGE(refcnt != 1, page); -> Verify that it is 1. > > I understand where this patchset is going, but this intermediate step is > not a good move. > > Also, for the overall series, if you want to change from > "set_page_count()" to "inc_and_verify_val_equals_one()", then the way to > do that is *not* to depend solely on VM_BUG*() to verify. Instead, > return something like -EBUSY if incrementing the value results in a > surprise, and let the caller decide how to handle it. Actually, -EBUSY would be OK if the problems were because we failed to modify refcount for some reason, but if we modified refcount and got an unexpected value (i.e underflow/overflow) we better report it right away instead of waiting for memory corruption to happen. Thanks, Pasha