Received: by 2002:a05:7412:1492:b0:e2:908c:2ebd with SMTP id s18csp143483rdh; Tue, 22 Aug 2023 15:43:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOVhYH/rhY8Y7IWDGdUk3wAeHfBP7pEcZBDB0i4TA+4vfxIhdcizXFKXJaHWUcH9c8022C X-Received: by 2002:a05:6a00:1788:b0:68a:6e81:60a2 with SMTP id s8-20020a056a00178800b0068a6e8160a2mr3357017pfg.26.1692744200376; Tue, 22 Aug 2023 15:43:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692744200; cv=none; d=google.com; s=arc-20160816; b=Wytxq7QbmLXuHhQ6FQYGVXjAJEPfzBwiYh7ulQz5GxQOJWUVb5OeWIsRDmJghSHeUx 1Ghckwpq0ZPGpNM1Si4kjO4rWtvmtvbcbUgxVA790Fvr67l4zGQXjcrkUar31XdHn44F yNZc4KqjcvAz54KZFQrgGBodb6/X4AAd1HwImN/lS29x+VK22M1tWPHRD8YaKAPfTfGK XnksLaPUO4L9QF/jjiCEucnGKtCTBV0P+7WfmfuAKmAVoiaLIozV+g1xN6rZMTkR8fm0 DOXmZu3M4RjVjhkOvytnt8+7qh+JIFyo63Aa+dKfwkBft2kUbyWzLv2lJt4N5jumgRln Y0wQ== 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=yzM5RKagZ3Wj/c+8PA3JPMN0SmPqMlqTSiJ+Vdr+aHo=; fh=6TkFTPxVPoB+BcWOAA8c9yxPsawB9207yQKVyE+Up6E=; b=nU7JN/es1d1/sisRUdhPMzmtYEnbuq9C3qcgsybW7Tl0dv1yAwR5uOYcuQP+L6IENt pJpL7kV33s7HGUOBfVXjosiyecz8etlP5KknEdjw+lLva5hC5HegdQuKp70ZvuJlXLpV yZ/zpWus3UhMqWf6mluTo9Rvew/YZaZznoAX+6Vrm1LHAq/Gy0w+K9YyMWBkUoOqzItN LE5V4A8aJH0OKwCEsg0UoHneiJ+bKHOASs1O+Lh91p6eBIHW0h7Mch/gSzbCON5NKwIN auy6k8CTAYjooKwlmGJHRh2FcmebXbHYF/4JAwxYMQ+4sJlfFPWCtu9K+EznAtN369OL yakg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PVLkMFsR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be13-20020a056a001f0d00b0068729f6be0csi9633198pfb.127.2023.08.22.15.42.59; Tue, 22 Aug 2023 15:43:20 -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=@kernel.org header.s=k20201202 header.b=PVLkMFsR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbjHVVe4 (ORCPT + 99 others); Tue, 22 Aug 2023 17:34:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjHVVez (ORCPT ); Tue, 22 Aug 2023 17:34:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CAD9CDF for ; Tue, 22 Aug 2023 14:34:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9607C65007 for ; Tue, 22 Aug 2023 21:34:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECDE2C43391 for ; Tue, 22 Aug 2023 21:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692740093; bh=sTYLGwr0V50j9YnnrrFQseiF978eUCHUgXKQmpVIZns=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PVLkMFsRPSng2FPiib+3A6/61y4RNXym38RbIxPyW9HbZZ2BJrVjeJLHLtHOBpEY1 wrBURY9+7Kn8oyi0dg9R85SUcsm1iFwfhF8Bm6+qbTcTOzz7d562p9v6LK3ckfM+kk +g29Z8Aoyiffdhft5NMxos7re6bdTWSWfQ5MP0hy3nDEktNARXtG7FaBdAwxuxfwIk AH+SjMCv+9/yLWmMZQMuSibDL3fU6Aaq/KrEpcO5ujfIVc62x9qLo7iwyq2u8mEi9A HvzshaU8OSTHlCcNRh03Lf1zyMB69PwdQ/fG+wZOckEgpo1r85pHkADugfPwNpzu7J IFo+ea/o50uGw== Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-26d0d376ec7so3419802a91.2 for ; Tue, 22 Aug 2023 14:34:52 -0700 (PDT) X-Gm-Message-State: AOJu0YwCP6WLGYxHORc56i/ddIK4UTmoIcUkde0HEQQ0h2EutWvN390P AZ7C2qNVlTq6mZ9qHYRF2G/bI1izC5CW3rxF/YxHXQ== X-Received: by 2002:a17:90a:fc8e:b0:26d:416a:d9d2 with SMTP id ci14-20020a17090afc8e00b0026d416ad9d2mr9625027pjb.45.1692740092376; Tue, 22 Aug 2023 14:34:52 -0700 (PDT) MIME-Version: 1.0 References: <20230817-free_pcppages_bulk-v1-0-c14574a9f80c@kernel.org> <20230821103225.qntnsotdzuthxn2y@techsingularity.net> In-Reply-To: From: Chris Li Date: Tue, 22 Aug 2023 14:34:40 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC 0/2] mm/page_alloc: free_pcppages_bulk safeguard To: Alexei Starovoitov Cc: Mel Gorman , Andrew Morton , Kemeng Shi , baolin.wang@linux.alibaba.com, Michal Hocko , David Hildenbrand , Matthew Wilcox , linux-mm , Namhyung Kim , Greg Thelen , LKML , John Sperbeck , Huang Ying , Alexei Starovoitov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Hi Alexei, On Tue, Aug 22, 2023 at 11:57=E2=80=AFAM Alexei Starovoitov wrote: > > On Tue, Aug 22, 2023 at 10:48=E2=80=AFAM Chris Li wro= te: > > > > Hi Mel, > > > > Adding Alexei to the discussion. > > > > On Mon, Aug 21, 2023 at 3:32=E2=80=AFAM Mel Gorman wrote: > > > > > > On Thu, Aug 17, 2023 at 11:05:22PM -0700, Chris Li wrote: > > > > In this patch series I want to safeguard > > > > the free_pcppage_bulk against change in the > > > > pcp->count outside of this function. e.g. > > > > by BPF program inject on the function tracepoint. > > > > > > > > I break up the patches into two seperate patches > > > > for the safeguard and clean up. > > > > > > > > Hopefully that is easier to review. > > > > > > > > Signed-off-by: Chris Li > > > > > > This sounds like a maintenance nightmare if internal state can be arb= itrary > > > modified by a BPF program and still expected to work properly in all = cases. > > > Every review would have to take into account "what if a BPF script mo= difies > > > state behind our back?" > > Where did this concern come from? > Since when BPF can modify arbitrary state? > > But I wasn't cc-ed on the original patch, so not sure what it attempts to= do. > Maybe concern is valid. Sorry I did not CC you on the original patch submission. I should. Here is the link for the 1/2 patch, which has the step to reproduce. https://lore.kernel.org/linux-mm/20230817-free_pcppages_bulk-v1-1-c14574a9f= 80c@kernel.org/ It is using an older version of the BPF program. That spinlock allocation was fixed in commit c66a36af7ba3a628. Chris > > > Thanks for the feedback. > > > > I agree that it is hard to support if we allow BPF to change any intern= al > > stage as a rule. That is why it is a RFC. Would you consider it case > > by case basis? > > The kernel panic is bad, the first patch is actually very small. I can > > also change it > > to generate warnings if we detect the inconsistent state. > > panic and warns because of bpf prog?! > bpf infra takes all the precaution to make sure that bpf progs > can never cause such damage. > > > > > How about the second (clean up) patch or Keming's clean up version? I c= an modify > > it to take out the pcp->count if the verdict is just not supporting > > BPF changing internal > > state at all. I do wish to get rid of the pindex_min and pindex_max. > > > > Thanks > > > > Chris >