Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1485405lqp; Mon, 15 Apr 2024 07:53:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX657ESKOtYvlnlxMSYMGIfmBzShjkqHvrYPwyqowfdFC/GNBO30COCI5+xmw4fAdUMc4A68aZjdveuaMwu24lyc21bpdx6c52OCQHiPg== X-Google-Smtp-Source: AGHT+IH0P6YddNT6SbkB20NZWvu4OcwufavkinyRwvR9Pt+2Q5BPd+cXWZTfZrBn+8c7IUE89bJj X-Received: by 2002:a50:a689:0:b0:56e:2fb9:66d6 with SMTP id e9-20020a50a689000000b0056e2fb966d6mr4458265edc.27.1713192789615; Mon, 15 Apr 2024 07:53:09 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h12-20020a05640250cc00b0056e6601fc9asi4517856edb.469.2024.04.15.07.53.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 07:53:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=PWrs5fKI; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-145390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145390-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 310C01F22945 for ; Mon, 15 Apr 2024 14:53:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE8AC757E5; Mon, 15 Apr 2024 14:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PWrs5fKI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB853679E5; Mon, 15 Apr 2024 14:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713192777; cv=none; b=nfQsGIXZk/KcRzhHspHbElF6AeBCMLJ78zbuvexALqpuJMnIjLKlE95NvxWkrgom2dNX+Q7RVemoMzcai04bXAHsO7BhIYl1neZSXCgJ5jhXNBQrpELlmYxTMYBWK/N+A8GZ0ctLurRNZ2Qza/GbHXw/gQmcXMjJbZj6Y8e7p6U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713192777; c=relaxed/simple; bh=NhbAtc6tAGccokWSTjoKOMtgLuAbLGDa8a3OfLwV230=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OLodLUgG5tV921jANIqjXwrZDqPDNMwnbtc448V9clnxuI5aV09SoRzAK/OxOvxDpzQLMJha6fGGYK89u9eWEbWCpydwXO/5Oqr23wiTNyRxvxKF3K/fFFBF8rDU8VOti+wLxyK2+syr3bfGEKnPervk9hUUQYUYli0HtEqL2wc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PWrs5fKI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 267E2C113CC; Mon, 15 Apr 2024 14:52:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713192776; bh=NhbAtc6tAGccokWSTjoKOMtgLuAbLGDa8a3OfLwV230=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PWrs5fKIlnzoyDAUHDWP4Y/Pvl09ehPKzlzipssc5llEgsM4XodZX0woW/NTST5B0 B03GQhlkgJcyHjeYjkF3SyUa20g6XEuS8KiTh2nzLYc3Gze0gL4BErAp+FmCxJDLqi bvUg4CwKXnhE2lYPOVePRzcbQQ8MsTc1venCKXnd1OzvhSY+Hnj1xlWlPSkFUF+Jvi bUpSa71+FXCgHH2/wOsYHf8ByDStbIrmopHRqOwEf0qZSD6UPlNaOMa+5qLAXv2G6P 0KWdSBJRQ3odCtfC+CFjNz5OBy/p8Co9ZLQ0bETvoKnFjr2C56WASlvyOKZAExb91o UjHI3ixedmu6Q== Date: Mon, 15 Apr 2024 15:52:48 +0100 From: Simon Horman To: Yi-De Wu Cc: Yingshiuan Pan , Ze-Yu Wang , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Catalin Marinas , Will Deacon , Richard Cochran , Matthias Brugger , AngeloGioacchino Del Regno , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, David Bradil , Trilok Soni , My Chuang , Shawn Hsiao , PeiLun Suei , Liju Chen , Willix Yeh , Kevenny Hsieh Subject: Re: [PATCH v10 15/21] virt: geniezone: Add demand paging support Message-ID: <20240415145248.GD2320920@kernel.org> References: <20240412065718.29105-1-yi-de.wu@mediatek.com> <20240412065718.29105-16-yi-de.wu@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240412065718.29105-16-yi-de.wu@mediatek.com> On Fri, Apr 12, 2024 at 02:57:12PM +0800, Yi-De Wu wrote: > From: "Yingshiuan Pan" > > This page fault handler helps GenieZone hypervisor to do demand paging. > On a lower level translation fault, GenieZone hypervisor will first > check the fault GPA (guest physical address or IPA in ARM) is valid > e.g. within the registered memory region, then it will setup the > vcpu_run->exit_reason with necessary information for returning to > gzvm driver. > > With the fault information, the gzvm driver looks up the physical > address and call the MT_HVC_GZVM_MAP_GUEST to request the hypervisor > maps the found PA to the fault GPA (IPA). > > There is one exception, for protected vm, we will populate full VM's > memory region in advance in order to improve performance. > > Signed-off-by: Yingshiuan Pan > Signed-off-by: Jerry Wang > Signed-off-by: kevenny hsieh > Signed-off-by: Liju Chen > Signed-off-by: Yi-De Wu .. > diff --git a/drivers/virt/geniezone/gzvm_exception.c b/drivers/virt/geniezone/gzvm_exception.c > new file mode 100644 > index 000000000000..475bc15b0689 > --- /dev/null > +++ b/drivers/virt/geniezone/gzvm_exception.c > @@ -0,0 +1,39 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2023 MediaTek Inc. > + */ > + > +#include > +#include > + > +/** > + * gzvm_handle_guest_exception() - Handle guest exception > + * @vcpu: Pointer to struct gzvm_vcpu_run in userspace > + * Return: > + * * true - This exception has been processed, no need to back to VMM. > + * * false - This exception has not been processed, require userspace. > + */ > +bool gzvm_handle_guest_exception(struct gzvm_vcpu *vcpu) Hi Yi-De Wu, The return type is bool, however the function actually returns either a bool or signed int. I think that either: 1. The return type should be changed to int, and returning true and false should be updated. 2. The function should always return true or false. Flagged by Smatch. > +{ > + int ret; > + > + for (int i = 0; i < ARRAY_SIZE(vcpu->run->exception.reserved); i++) { > + if (vcpu->run->exception.reserved[i]) > + return -EINVAL; > + } > + > + switch (vcpu->run->exception.exception) { > + case GZVM_EXCEPTION_PAGE_FAULT: > + ret = gzvm_handle_page_fault(vcpu); > + break; > + case GZVM_EXCEPTION_UNKNOWN: > + fallthrough; > + default: > + ret = -EFAULT; > + } > + > + if (!ret) > + return true; > + else > + return false; > +} ..