Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4691320rdb; Fri, 15 Sep 2023 09:22:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbSGY6ziLHZmhU1Zmf9a6bVpIXeeYE5+kKmEEGQ9gb/4pNIJxOLOtyWWCVuTa1LaZFkvOq X-Received: by 2002:a05:6a20:4406:b0:140:8537:85c1 with SMTP id ce6-20020a056a20440600b00140853785c1mr2649015pzb.28.1694794950552; Fri, 15 Sep 2023 09:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694794950; cv=none; d=google.com; s=arc-20160816; b=RXTFuHpaEdVMBU5ngEWxNL2NB8b16UC4KlmVQ3dtXjRCgSrIor1ri2LeLULH2MeXYl srWVyh9MN3cLWKnp/AsYelcA4fhpTGwro4T/vENaYfsL02taYPdZ75yQHbT2GMAZwVVk ihCENmcDP2RxYntOYD5KJbKvGlh1Xf9M1nM0ZnbgNyviU42oqQl7K5wlUl10NUwu3s71 YLmR1UJCzpB0Cy5qqh3JH07xKFxxAAezU97UhpJk4wHHZzGtL2GTNkQY6JA+4d+JjR6y 0WT9/PXKCgCMCzCLOzQ2RM5/8bE0xdQuXpCA8FsuxY9cEYQcEDAp46uAHDJsub7DAQx7 /7QQ== 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=a5dc0RapsJHRQN53o8cJrIr79i5yRR+ziDw1tWj/hHA=; fh=F2PphcgzXQSbhBek2e0EVROS2bF5NzuDz3LHN687m7E=; b=AJsvTUWCvZJUgqvcpmzLbBMo/sS0Zqr5yMLe5sBDKFMDJTpaqM+SQ6nPQ5Nq05bpDV xyI9r46oxQvino8TBiP5gAhLfM+CwO940mQQfQ5s/EpZra5CKbm4eVwyna5JhwnJKi45 bCk62CYTuJ1ibCyRHa4RmcQAFvm8QHd1sGJvE6oXclxP8HC9PBzyWhs3QJervfyvTrMB 3hsvsypYPjFMZQfDeRPIZIQDxQE3be20wfZzemjAJ3LyAKSVvW+6Bi2Hz3/K0oPGtGY4 dQ+GnM9//DVwcDMFckSnve0IIu4OOwgLAbazy/8crAWH/9PJZZ6t/mfr7h1etVzTNHAF lAQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QfIxft7I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m1-20020a656a01000000b00564a1716ebbsi146844pgu.697.2023.09.15.09.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QfIxft7I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 584F482A38C0; Thu, 14 Sep 2023 22:47:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232149AbjIOFrW (ORCPT + 99 others); Fri, 15 Sep 2023 01:47:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232141AbjIOFrU (ORCPT ); Fri, 15 Sep 2023 01:47:20 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8EB02719 for ; Thu, 14 Sep 2023 22:47:14 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bfc5218dd8so27298281fa.2 for ; Thu, 14 Sep 2023 22:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694756833; x=1695361633; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=a5dc0RapsJHRQN53o8cJrIr79i5yRR+ziDw1tWj/hHA=; b=QfIxft7IqHZLgWnz3JpSP9uxqXMnmkfORydpkR7+HIFHhc3MHEvLkfxZBSs3gDNdfU FT0NxiO3c4uzVjuIUwGcT2z35h6xPN2a9m8Qs88aaYY5skMysZD4cM+A/xgbUalTvuyT +YuZJS5kj4/FBP6z29+Ii79e+Ru4hCKnqPS0y/SDB0HynovWt2qL4pPc7LvoMzYST30c s8ba7oujFhgLE9VjonsNzlWn7EIFux/IELkOyMaGmid+SFb1vyZGGB6w+s11A2z514N6 gzYfC9t9V3k2LMcHAbjdE/KpafCng9tRIFD9P31ZGALEy7Fqj/vEJlZhXG1gEaU2rmrG jxxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694756833; x=1695361633; h=content-transfer-encoding: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=a5dc0RapsJHRQN53o8cJrIr79i5yRR+ziDw1tWj/hHA=; b=cpFEJ3MdWjUn0q7H7VBtvoBjtjo68RPKpoic3zPrnbjPie0nSmpSCrCoHl9Ix7e/7a W0BBpL4C2dye2YTok+Vntg8vEKr4JkuRQpdiqQ4X5ivT6t5gp8b/03fna0RWqkziZFvy ssw2foQJCOaFLYiArraau698nb8jNlP6l2Ev5y3siMliKaL6My+lBiIAwAnizBYlX+sp 5+ojXFpzSxc36daVo0YBGuOwHskfVX++MCUbaC0WTUaRhV4I/cjeavtXMWQjSxqGR7jF 4xv+cw/IbGuxf3ndGIxTlsElpxbrUKix99ejHxwDUfSZ2wyuOan8yxsNMFPkqncE8M+f GXFQ== X-Gm-Message-State: AOJu0YwBSm2avD51OEIC30oykh5MdbtXr/BK6cxfJi6M4G9yu8g8gQmD lAFwpCLaWnHnoQHEQcBjRm+baHv0+KKaM9kMcHM= X-Received: by 2002:a2e:494a:0:b0:2bc:d634:2210 with SMTP id b10-20020a2e494a000000b002bcd6342210mr623143ljd.16.1694756832856; Thu, 14 Sep 2023 22:47:12 -0700 (PDT) MIME-Version: 1.0 References: <20230912103334.2074140-1-zhaoyang.huang@unisoc.com> In-Reply-To: From: Zhaoyang Huang Date: Fri, 15 Sep 2023 13:47:01 +0800 Message-ID: Subject: Re: [PATCH] arch: arm: remove redundant clear_page when CONFIG_INIT_ON_ALLOC_DEFAULT_ON is on To: "Russell King (Oracle)" Cc: Matthew Wilcox , "zhaoyang.huang" , Andrew Morton , Mike Rapoport , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ke.wang@unisoc.com 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 22:47:22 -0700 (PDT) any further comments, it is arised from a real performance issue observed double times of memset in ARM A55 which should be waste. What this patch suggest is to remove the latter one while ensure the page will be cleared under all scenarios On Wed, Sep 13, 2023 at 4:53=E2=80=AFPM Zhaoyang Huang wrote: > > On Wed, Sep 13, 2023 at 4:17=E2=80=AFPM Russell King (Oracle) > wrote: > > > > On Wed, Sep 13, 2023 at 09:13:14AM +0800, Zhaoyang Huang wrote: > > > On Tue, Sep 12, 2023 at 8:18=E2=80=AFPM Matthew Wilcox wrote: > > > > > > > > On Tue, Sep 12, 2023 at 06:33:34PM +0800, zhaoyang.huang wrote: > > > > > From: Zhaoyang Huang > > > > > > > > > > Double times of clear_page observed in an arm SOC(A55) when > > > > > CONFIG_INIT_ON_ALLOC_DEFAULT_ON is on, which introduced by > > > > > vma_alloc_zeroed_movable_folio within do_anonymous_pages. > > > > > Since there is no D-cache operation within v6's clear_user_highpa= ge, > > > > > I would like to suggest to remove the redundant clear_page. > > > > So if CONFIG_INIT_ON_ALLOC_DEFAULT_ON is not enabled, then what ensures > > that the page is cleared? > > > > > > > > > > > > > struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struc= t *vma, > > > > > unsigned long vaddr) > > > > > { > > > > > struct folio *folio; > > > > > > > > > > //first clear_page invoked by vma_alloc_folio=3D=3D>alloc_page=3D= =3D>post_alloc_hook > > > > > folio =3D vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vad= dr, false); > > > > > if (folio) > > > > > //second clear_page which is meaningless since it do nothing to D= -cache in armv6 > > > > > clear_user_highpage(&folio->page, vaddr); > > > > If this clear_user_highpage() is removed, how is this code then safe wh= en > > CONFIG_INIT_ON_ALLOC_DEFAULT_ON is not enabled? > when CONFIG_INIT_ON_ALLOC_DEFAULT_ON is off, want_init_on_alloc() will > return false and then clear_user_highpage will be called > > > > > > > > > > This is, of course, not the only place which calls clear_user_highp= age(). > > > > Please explain why this patch is safe for all the _other_ places wh= ich > > > > call clear_user_highpage(). > > > Here are all positions called clear_user_highpage which are paired > > > with alloc_pages. IMO, it is safe to skip the second clear_page unde= r > > > armv6. > > > > No. > > > > Looking at, for example, the v4l case... This allocates a page and > > provides it to userspace. The page is allocated using GFP_USER | > > __GFP_DMA32. This does not set __GFP_ZERO. If > > CONFIG_INIT_ON_ALLOC_DEFAULT_ON is not enabled, the page will not > > be initialised, and thus we will leak any data in that page to > > userspace. > as explained above, clear_user_highpage will be called in this scenario > > > > Now, it's not just about whether that configuration symbol is enabled > > in the kernel configuration - there is a command line argument to > > consider as well. CONFIG_INIT_ON_ALLOC_DEFAULT_ON can be y, but with > > init_on_alloc=3D0 passed to the kernel, if we remove the above > > clear_user_highpage(), the kernel then becomes unsafe. > Both of CONFIG_INIT_ON_ALLOC_DEFAULT_ON and cmdline configuration take > effect via the global variable init_on_alloc which is judged within > want_init_on_alloc() > > > > However, it's more than that. The kernel allocator has no idea that the > > page will be mapped to userspace, so it can't do the "clear the page at > > the user cache colour" trick for VIPT aliasing caches, which ensures > > that we hit cache lines that the user will see. So, I think we would > > then have to add arch specific cache operations to write-back the > > zeroing of the kernel mapping, _and_ cache operations to discard any > > data in the user cache colour. > ok, do you mean you will update v6's clear_user_highpage from memset > to D-cache flush things? > > > > So, essentially, I don't think that _even_ when init_on_alloc is > > enabled, we can skip calling clear_user_highpage() as that would lead > > to data exposure to userspace. > This patch only suggests making changes on the specific v6 > architecture where clear_user_highpage equal to clear_page so far. > > > > -- > > RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ > > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!