From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0C6CECAAD5 for ; Mon, 5 Sep 2022 12:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=42FC+jaW/KF6npsATe42DCXuW82G1h2xCTDnX3BqaEg=; b=DUw4PX3M3049GH 537SU3xceCSFwYHkFB91yLazaanzUVfNT3lybi8ebzuSIqP3vqv9wzeN36D0TUbysDstgShmMWKGY tZHWm+mlm9lcQCbJ7xyyMcDilpq9jMc/foxtqvi1E8Epf2GkcEI6OSdaFFIWQOXoZDU1M+aixvvH6 9hGLhqFD9DVvSjnJNzJImGAAAgm1eXnSjmOtFv8szBISLSbnJ71r4d0qLkthcQbvoi39c9dnZ380v epfaQWKQew9VcfGF7LjQmUI//Du5r71+wQsVIo5lSgCFqea0EtGtTqgrhb5uXD4ndhp+xsIYSmCPw T/8u0TL6mik3xshrzA2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oVAqP-001lrP-4Q; Mon, 05 Sep 2022 12:04:49 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oV9EZ-0007Cm-TA for linux-arm-kernel@bombadil.infradead.org; Mon, 05 Sep 2022 10:21:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=WOiQyNrs1be4WayrMavedXF8G5KASrWmWSypKhmVsIU=; b=hXaJhQ9gfSV3cUK3+7lx7zBuYZ UGybx6wyKOep1xwx76CKtImXB5ydW/H4Ov+aTQ3s1Zc4+LwBgLAzIi5EycP8EmbjReUHj+/PgF7q6 WHUQxuZ3VMDhQM68oG6RWSeHHP/ooqIvWOaVOUNYOq9V3NgJGgh2It4P4pldprWT0HV5ily5fu8bo /7HBLYyHIWyqVxW5VNLAx6kTbEd6u+C33bxJLBlTJ2RJP41qciOUl1RxsQ96iEbburBjRCUMRtDDk KXvek+Fb7NnBCQ+kqkkWf4GhdQpyufrugGETnbaDgbYXJpyKobWyw4gvH9twcwnYGn4NwkJxNU7px 8TdjbRyg==; Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oV9EV-009VZU-MI for linux-arm-kernel@lists.infradead.org; Mon, 05 Sep 2022 10:21:37 +0000 Received: by mail-pj1-x1035.google.com with SMTP id fs14so3217340pjb.5 for ; Mon, 05 Sep 2022 03:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=WOiQyNrs1be4WayrMavedXF8G5KASrWmWSypKhmVsIU=; b=hFivwXjCJgNMTE0WKvMzT5WXMBkAIJt6CXI1uU+pYsutcunyv4eOdClS1rnDdJfIUJ JfIWgE1craEdhAv4qmADejmOiU7u9LJeONE/Yr3LsLPBwyJ5wH+Q5Tb+ur3H369in4JP T/DNHfOAE/UbkKZFBtVZEDlJL1Y/8dImJkvXb+KcjW/DNdooHos2MbZD/4dVoOOZSrij fjjsU1FG8eddTxJH1h4qcROGXq7906yrGQZcry+fuPWRJ2DYOVEN1X5oXlR9CHMDwkwH Osc8B94EhgUbxKIAqLpFX2eNUJ+99LuVu39rjBvi2EM1Kjr5LAcywTtmMcYvlJ2Tw1IT SLIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=WOiQyNrs1be4WayrMavedXF8G5KASrWmWSypKhmVsIU=; b=V0wdstQ14cZ8tNLnaFFYmKiGexrjBbj+KF2DDbpkLtYn5KBMxITLOJrhz95TKTCRoG CQfCZQf+dXZA0SvbRm3WqunnJ6lIWTEmqp9JOlL8WsE4CQ0FEZja9RO233QKjd4NiZBo tFcNK/5OM35xZXoljw6HU0BwhvB9ksFjVLt+uggJOsm0HuoOsj87OQzdanR+PnngZ4tX 7Bdr60LlLDBYpjM3Rcp/VAQWiLyrx6Vf4Tuxa7fiuDaZ0k8LegaPy54c1qmaefwauL3f z20EZy3mW7lmaNZZV0RsgB57zvHH/uII7SvMuKXKm6FFdJ3ftC+hlx4hkF8ODsdwcFE6 plQg== X-Gm-Message-State: ACgBeo0HGandhDkDJgJ7FKfEnKtZxK0GDcQhzx9RR7BL9otq7Fnw6Q0l pYJKw/XjYYhoe7MWWTHmRl8= X-Google-Smtp-Source: AA6agR7LIPqTF9y5KMw44brYpz00x4KtHrMLzckeENRVkFHugvHjNVUGpZGbBHlt5s41DmP5uDLinA== X-Received: by 2002:a17:903:189:b0:176:861a:d4d1 with SMTP id z9-20020a170903018900b00176861ad4d1mr10195220plg.154.1662373289692; Mon, 05 Sep 2022 03:21:29 -0700 (PDT) Received: from hyeyoo ([114.29.91.56]) by smtp.gmail.com with ESMTPSA id d14-20020a170903230e00b00174849e6914sm7095326plh.191.2022.09.05.03.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 03:21:29 -0700 (PDT) Date: Mon, 5 Sep 2022 19:21:24 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Jeungwoo Yoo Cc: Catalin Marinas , Will Deacon , Gwan-gyeong Mun , Sangyun Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: Remove d-cache clean operation at preserve_boot_args(). Message-ID: References: <20220904193020.65556-1-casionwoo@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220904193020.65556-1-casionwoo@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220905_112135_935309_298F668B X-CRM114-Status: GOOD ( 32.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org note that I am not an expert on arm64 so I may be wrong, and I'll be happy to be proven wrong ;) On Sun, Sep 04, 2022 at 09:30:19PM +0200, Jeungwoo Yoo wrote: > Kernel expects only the clean operation as a booting requirement in > arm64 architecture [1], therefore, the kernel has to invalidate any > cache entries after accessing a memory in the booting time (before > enabling D-cache and MMU) not to overwrite the memory with the stale > cache entry. Yes. > Same applied in preserve_boot_args(), kernel saves boot arguments into > 'boot_args' and invalidates the corresponding cache entry. However, > according to the 'dcache_inval_poc()' implementation, the cache entry > will be not only invalidated but also cleaned. Yeah, that's when @start or @end passed to dcache_inval_poc() is not aligned to cache line size. and @end may not be aligned if cache line size is not 32. (@start is always aligned) > That means if there is a > stale cache entry corresponding to the address of the 'boot_args', the > saved boot arguments in 'boot_args' will be overwritten by the stale > cache entry. To clarify, "If existing cache entry became stale after writing to memory..." > Therefore, it uses 'dv ivac' instruction directly instead > of calling 'dcache_inval_poc()'. > > The address of the 'boot_args' is aligned to the cache line size and the > size of 'boot_args' is 32 byte (8 byte * 4), therefore, a single > invalidate operation is enough to invalidate the cache line belonging to > the 'boot_args'. Is the cache line size always >= 32 bytes? If I'm not mistaken, the minimum size is 16 bytes. > Sometimes clean operation is required not to lose any contents in the > cache entry but not the target of the invalidation. However, in this > case, there is no valid cache entries at a very early booting stage and > preserve_boot_args() is not called by any other (non-primary) CPUs. > Therefore, this invalidation operation will not introduce any problems. I think this patch makes sense. Losing data in invalidation operation is not a concern for booting process. And it may lead to writing stale data to memory if: - a boot loader only cleans address range corresponding to kernel image (and not invalidate) according to booting.rst Thanks! > [1] in Documentation/arm64/booting.rst: > The address range corresponding to the loaded kernel image must be > cleaned to the PoC. > > Co-developed-by: Gwan-gyeong Mun > Signed-off-by: Gwan-gyeong Mun > > Co-developed-by: Sangyun Kim > Signed-off-by: Sangyun Kim > > Signed-off-by: Jeungwoo Yoo > --- there should be no newlines between tags :) > arch/arm64/kernel/head.S | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S > index cefe6a73ee54..916227666b07 100644 > --- a/arch/arm64/kernel/head.S > +++ b/arch/arm64/kernel/head.S > @@ -121,9 +121,7 @@ SYM_CODE_START_LOCAL(preserve_boot_args) > > dmb sy // needed before dc ivac with > // MMU off > - > - add x1, x0, #0x20 // 4 x 8 bytes > - b dcache_inval_poc // tail call > + dc ivac, x0 // Invalidate potentially stale cache line > SYM_CODE_END(preserve_boot_args) > > SYM_FUNC_START_LOCAL(clear_page_tables) > -- > 2.34.3 > -- Thanks, Hyeonggon _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel