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 2F478C27C4F for ; Fri, 21 Jun 2024 09:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BoQvFg8b1unfgD/u5vo+Z+b74zJDMogaMP+B5tsqbzk=; b=SitfQpQZ1X4512farBy5sWenOn NZnUuYt3FkqxE/kPnOo0CU5+avH3CAcctGbQznolZNO3Tjw2KASZzJQ6lHtSRZ5glo8aKfpd4tiFO +qvfNIGqQU/bTs9r9y2BJz31nCxbJcM78AvljZu3D3MP8q/WUg9smDwV80Ru6rNHY412H8jg7m8s2 yJklkTFQA0OBP49SG1BPEYfK9dOKi8T/89id+UlTcEQQoC14L/lvnf7XplaccpsMahZfboy5iyDS3 bcKS98wWvha0VYtp4YWeGVVx3gBqTBkGfIxmy4m9Q+JHxMCae264YQFkPnTIKxCX5XqSb2bKZCFRn dvYl8zYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKaDO-00000008TjA-0WnP; Fri, 21 Jun 2024 09:05:50 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKaDK-00000008Ths-1LSF for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 09:05:47 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id ED32F6248F; Fri, 21 Jun 2024 09:05:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FE7EC4AF09; Fri, 21 Jun 2024 09:05:41 +0000 (UTC) Date: Fri, 21 Jun 2024 10:05:39 +0100 From: Catalin Marinas To: Steven Price Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Suzuki K Poulose , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni Subject: Re: [PATCH v3 09/14] arm64: Enable memory encrypt for Realms Message-ID: References: <20240605093006.145492-1-steven.price@arm.com> <20240605093006.145492-10-steven.price@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240605093006.145492-10-steven.price@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_020546_770694_F01A2B06 X-CRM114-Status: GOOD ( 16.17 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jun 05, 2024 at 10:30:01AM +0100, Steven Price wrote: > +static int __set_memory_encrypted(unsigned long addr, > + int numpages, > + bool encrypt) > +{ > + unsigned long set_prot = 0, clear_prot = 0; > + phys_addr_t start, end; > + int ret; > + > + if (!is_realm_world()) > + return 0; > + > + if (!__is_lm_address(addr)) > + return -EINVAL; > + > + start = __virt_to_phys(addr); > + end = start + numpages * PAGE_SIZE; > + > + /* > + * Break the mapping before we make any changes to avoid stale TLB > + * entries or Synchronous External Aborts caused by RIPAS_EMPTY > + */ > + ret = __change_memory_common(addr, PAGE_SIZE * numpages, > + __pgprot(0), > + __pgprot(PTE_VALID)); > + > + if (encrypt) { > + clear_prot = PROT_NS_SHARED; > + ret = rsi_set_memory_range_protected(start, end); > + } else { > + set_prot = PROT_NS_SHARED; > + ret = rsi_set_memory_range_shared(start, end); > + } While reading Michael's replies, it occurred to me that we need check the error paths. Here for example we ignore the return code from __change_memory_common() by overriding the 'ret' variable. I think the only other place where we don't check at all is the ITS allocation/freeing. Freeing is more interesting as I think we should not release the page back to the kernel if we did not manage to restore the original state. Better have a memory leak than data leak. -- Catalin