Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp694478pxb; Wed, 27 Oct 2021 10:32:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyshLlj4uQviNGRPKY/beusd39cm6ZbhcicuBocuvFNT4EqW0XGMG0XGC2A9kAeA4OzokHZ X-Received: by 2002:a17:906:17d5:: with SMTP id u21mr39868190eje.16.1635355839287; Wed, 27 Oct 2021 10:30:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1635355839; cv=pass; d=google.com; s=arc-20160816; b=V3kkEk37c//x1khYo/iHNatJYatBhkER0D26tZDgLAFNFvChA6McD8qlLv7x1AeccO KEjXOh63d+UmRpmjkKtZM4CkphrdVBmVQjlKE7BLQ6QtgVVzPsSnEnv0z2uIuDA4xhv4 a3Jnkdt2c8HjtbnJgd0oO70HLTLd1T5emtyUG4dkLWGaq0ZVJRTiWLXd4Vp/4iK1N/06 IZWH6fDsogH2OUfnFOIXTE/QOYrFeeaoT0EtlOeBtMdE8f0GrLLYK6eSiZtUtHWlRMXH QdkHbq689FimwF/vDVxTJ0dRYgEgHf7ryEtIwbhlv4SCQmrXoax2WqOE7xch11WGtj43 tHHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=Ew9WY2TQmM/NVs1P/DEBLSBwfyNFuVYypHUnZ30vQLw=; b=PjGx/iuiynWsK9nAeSXKjNFoJ258dwX/NZ8o29MjsIQ6S9MH9TEKCrVzqd0fknYNn+ 7oiYCoMXIZ1lbUHqypq3nz/Nlc/P1jOctxDSfBegWSrykk9pJ9i8HmH8v9Crni99DQQs pe0Wos1smnxh7RDpHswhqcXVIG9SBBl9NbjIRBThCLm9lW/ZN5s7LBxNC7IYcrI35/j8 NJtES0jrhTc4nJGtsnNllI5FBge2hslbi4XZCmhWNQK4XsZDvThZbrDkzmf5/oo8LgmF CofYpgfpkUuYEK9cKoXA/TfW8d3Q/oYbQQAsrhfRoW6YhP7ZH7UXh4wzLnjo73wB8PMg IFTw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="EKZ/iMjB"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si695680edc.614.2021.10.27.10.30.02; Wed, 27 Oct 2021 10:30:39 -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=@Nvidia.com header.s=selector2 header.b="EKZ/iMjB"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238166AbhJ0FOp (ORCPT + 99 others); Wed, 27 Oct 2021 01:14:45 -0400 Received: from mail-co1nam11on2056.outbound.protection.outlook.com ([40.107.220.56]:60896 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236866AbhJ0FOn (ORCPT ); Wed, 27 Oct 2021 01:14:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YFSSCtbfNIMKi7NolJ4CfcT7oMHpEGdAussg9/7JsjVns9BAAY7J52O2zDlhk8avfK7RgJVR5YwI0BPwu76K5myUn5DsuXMYNEzzA6OVCl53nQhjBIHU3sls/4lFkixRniS5x1CqgD9fRufMHKYKhpy+zgEZkiF7RPz13HvsUdLKi0xWyyB9sFpggLiFZX5YSc8/sE8EwP8HtDHaHrBpbTfhcG2Q2Ex5Eh1ox/qEaeep70c9vOzYTzvD/z66NTe21Db6w79/s0yn4lELZYGoKq7wy1guOUfv67FKgGGVLBSi4zV1X1wLk2vq+RqL4l+Pt5XNnp4j7LP4za5orKq7aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ew9WY2TQmM/NVs1P/DEBLSBwfyNFuVYypHUnZ30vQLw=; b=BbU4Lpg+3Hdh3dQ+VRcAPLh8LYB0akYybLfzrO5r35/HcWgexvN85ZBRcep/BrFRiIf01TjoEu2aiZAviezBAxBKUEfRIHh13ExH0EHGYOMd3cRG2zrPWb0Rn50+KAPwirO6JXf8xJalwzMSH08BlKqAwJleTe+6nBbX/uMOMiENF3zC26cZAABhnnLfbJPkd6Jn78ugPwiKjAe8UzETVdFxYnBz16uR6H22PSAKG4HkJ7UrIfyAOzg5DautZ4zbe6WgztfgyquJsdTVJOii3No2PBy3L9LbMW3y3ZaJP98BOJkW+wcaD/f1wePknMpFFQWtEeAAkoRC4KA8k9+Kyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ew9WY2TQmM/NVs1P/DEBLSBwfyNFuVYypHUnZ30vQLw=; b=EKZ/iMjBLvWtUnkSjNoP7xucnkEYUwEKB+MWHP6IhxluJgP4DxoFKnlM21aB0j6YMrabGHXNxdyZJyp0M/yN8QTFwUnyaxFnhQDGsFuYsQEvUwV4uPuMf2FcafAAm8np67dAo1c8Ukcd65ZGJfGqBpD9lOPpwH5dZvV2R/7CO7syA/fT70OnMndgiKlROsOxSNtw8GBNEjtssUkBT6NVcjZM0sMvIF8hD0Rmy5pdGGVsTyZnCH8cW6QBh7b0mkJCdBLFMEvesIOcp8VD/JRwCvbaJyxPp6wfNEIEt3+rHYZ5LIJHXgqC7cB0IsJJcmi+RUSL+Li813G0tPJaN69C5Q== Authentication-Results: soleen.com; dkim=none (message not signed) header.d=none;soleen.com; dmarc=none action=none header.from=nvidia.com; Received: from BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) by BY5PR12MB4935.namprd12.prod.outlook.com (2603:10b6:a03:1d9::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Wed, 27 Oct 2021 05:12:16 +0000 Received: from BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::a0ac:922f:1e42:f310]) by BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::a0ac:922f:1e42:f310%4]) with mapi id 15.20.4649.014; Wed, 27 Oct 2021 05:12:16 +0000 Message-ID: Date: Tue, 26 Oct 2021 22:12:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [RFC 3/8] mm: Avoid using set_page_count() in set_page_recounted() Content-Language: en-US To: Pasha Tatashin 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 References: <20211026173822.502506-1-pasha.tatashin@soleen.com> <20211026173822.502506-4-pasha.tatashin@soleen.com> <7b131cb1-68d8-6746-f9c1-2b01d4838869@nvidia.com> From: John Hubbard In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BY3PR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:254::18) To BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) MIME-Version: 1.0 Received: from [10.2.61.40] (216.228.112.21) by BY3PR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:254::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.13 via Frontend Transport; Wed, 27 Oct 2021 05:12:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9fb5b45f-adbf-48fb-e1e4-08d9990857b0 X-MS-TrafficTypeDiagnostic: BY5PR12MB4935: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TshTbNuj/fUrg30hukLVXBEOMkcIW0rnY9HiJm+Czd3RtbcXyD9zB4LorusqXimBgF7jXYPBLOvZGGPIuz6qbQOLLbXiLvCDxQAVAcybWX90ypX/4pvX/w5IugSvkuQ2fxf7+pgqcxmIx4HZTaC6hTTKd3EfsBsI00jh7ljp8bd1ZNK40Usf3HGIXYOGV3rUXL1cU5MZm4Ht9dIUMlPzjLFNuFddYpeav0UQ5FVrRNtmJgRJQhHXxUN26rRg9bdWEKucLTboH0GtIzR9yhjBbpimMsEbYLrZrP2H1NJXvgNAqef5u8Oyy27Ldw/L4+ov+lYyuzBCqpNpHHGK3ja+c9gpIZUrTkc5oCuO8qOCE6LQ+SCGk49IjB0htSzgsL5bys2flfIZqIR4ETQ0RkUDGgz3LKrh5EgE0iawiBI1uY+43kZAkTqSc3LByuWghGmJlhNtsWNWRbRsnWqqef4Vzcu7nZ3axPSFgr80aYkI4X70L0rSShoeKa4zOvA3rv0fagMHT485FbAHRAb2cOE0rAZRL1hpjavODAXB11DJ5ZhbFuQ2RkFKhMJSNs06kQKkonkLwJlgsYiqnsT7Gj5QBmrAZNnJHFBr9oeAHDntkla/YtvRFBeiiOMQTE0u1uPzJN+CvoGHfpKlTKe9e51KAHQwNS/nr8yP4Lf5/Rjv0kOa4zF/9Kxgq8KuK/6gUF1KE9vnbedAx/VernCKaDzSiNwcmfQDmz5m/vr0EgwGcL0mNxfQJPXRGT6o85yiAY7/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB4130.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(508600001)(38100700002)(31696002)(6486002)(5660300002)(53546011)(26005)(186003)(8936002)(86362001)(2906002)(8676002)(7416002)(31686004)(2616005)(16576012)(66556008)(66946007)(956004)(36756003)(66476007)(4326008)(316002)(83380400001)(54906003)(6916009)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MEJiMGg0a2IrR2JDQmNoWkNDaDBSVHJzWU52SENBc2xQVEZWUmEza2Zzbm5Y?= =?utf-8?B?eFhsZVZETGpIWmhXRGJkd2RjMDV0NStyQ0lVQ0IvdysrYkVZQm5mRVExKy9Y?= =?utf-8?B?dmJYRWN1RDZPZGhscERFNmpOK3NPVUk1a1dicEJoaC8xMXZYemtYL1BaZ293?= =?utf-8?B?TG55MTd5ck5yYkJ0Ry9naE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Y1?= =?utf-8?B?NGZlWTNNWnpOQ2FtN3BEU2VvRWV5K3pIQ0MrMlNQVVdsa0J2WnhUWEtzbVpn?= =?utf-8?B?NEdRZncvNGVpZGt6NW84NGg1UTlCKzFnZXFwcXhXbHQxdVJha3YvV1FscmpX?= =?utf-8?B?WmxhaGY3NzM2dHZQNFlGSVlaQ1lJN2YxRi9ZQklsVC94QlI0OEtOakplUlo4?= =?utf-8?Q?4WPSbGdcNmswdbzxcnNx99k=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fb5b45f-adbf-48fb-e1e4-08d9990857b0 X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4130.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2021 05:12:16.3765 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RE31yhqWB5eYDKMxbSITiF4XrMXD6gz4RdpUTRwrxnNyZ8s/kb522i42KiqNvxc70xO5LlRKv0N4Hlulg1BFsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4935 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/26/21 11:21, Pasha Tatashin wrote: > 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. > Yes, you are just repeating what the diffs say. But it's still not good to have this function name doing something completely different than its name indicates. >> >> 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. > Having the caller do the BUG() or VM_BUG*() is not a significant delay. thanks, -- John Hubbard NVIDIA