Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3012451rdb; Tue, 6 Feb 2024 04:53:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQNQ1FSrMoS0YA6X4drnWD8XJD5jw7re9q/8eMuFrEtPVxEpBXl4oMdGAjN5gjQiv/0XID X-Received: by 2002:a05:6808:640a:b0:3bf:e5c0:6eb0 with SMTP id fg10-20020a056808640a00b003bfe5c06eb0mr1072693oib.19.1707223991985; Tue, 06 Feb 2024 04:53:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707223991; cv=pass; d=google.com; s=arc-20160816; b=CXXR+pHA6/KFVmM9W4mogdlIqN6nl9qltpppK428eofuu+QuLLxFHeLBln2r3Zx3BP kjbP2qgUFx8ntk/ZY0FH2M//n2RtZ+1NE6Rbeddp6LtjlvsNfH6a+orrxG7qQsGhkuxx es1RQVvxxB8T5SUTXHjqQpZCBjQHo6rSWHfh+BRX4uIVGgBrRPHtO3N1DQV7qQ6ew2R8 QIfHqn7leD4B4KdsQVPE9vJlicZvmFEG/kjCP57imIiT9GAibU6FdUiCHh2mXfmtay4l mxbnrC8Vixp4fpM6PQDeWvjEuKA+OWsKHu64q6u/nM3iSBcKGZSY1LoqzMeHLH45eLIV 1emg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=yLgYE2N3Nv0NXGIWZfh23pFlhWTS4CqcR4WiZpmW6VY=; fh=TTtVrAj1rBbCtSchuLdKqhzVFTNfmuvSvo3asCjR/ds=; b=PXPS0vkykdcKuQES9tehZj+t+4IbvJdoOzV60j7rd+5BRGohXttvYhp6wYD2gtgJUU y4dqknv5hsj0nmxvU4cl8R87t6WgjY+VFoPVcmcGvXUGuYnMznnNAA3wawS9vb9F2NP2 H/he5UeEHCmHJibWQwh5AYcAld0IFNC4YVaI0XL1YQmG2PVuUEXXo6m4HtDq6xCZO0Ua /lcOZ9bro8dFhjzNj/9MIp+EZLc6AYoVOcm5rrLO8/hKmMnIlID21cBQ/7GpN1PexCBh GzkSvRkc4RoWZyXUf/a5KiUVXzyzuIjTH9BQwvNDYrr7eAGzVe6AZ/U65kNpk89RmSxo vh4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k29cbhWS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54966-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXDv9YmldnayTswVyPtCb2Z1R5qunSBhE4YrPwRmf1Um+A/2bIAw39xQvU4xtuyNDFYlcE8r22zC2NA9VF9GJugDppw/euOWc4D/6E0pQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v3-20020ac85783000000b0042c374972a7si939098qta.124.2024.02.06.04.53.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:53:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k29cbhWS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54966-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6C8661C244B8 for ; Tue, 6 Feb 2024 12:53:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F15C712F39F; Tue, 6 Feb 2024 12:53:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k29cbhWS" 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 1357E12B142; Tue, 6 Feb 2024 12:53:04 +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=1707223985; cv=none; b=FusSo9qE8XQHQcrtfyzota0vcFBlEvcAW24MMb3NxZUtB3/ayr05F+5rS9QHpNqNngpFJVqw6oIoqxnabbVIGHnlorFr8guYNJm0LMKiYeAKDuShnbftILhuAxubj027xfb/WjzZ6Yk52zKUUYuAMMWJfZRqqs3+RLuapoZjsO0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707223985; c=relaxed/simple; bh=cC1iXIgYkNIh5eG5Gpxr3dx4+vBY/05hPu9acNFeElM=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=hiTma7j0FwE8MZlBsDHjNMU8ziZ4EEfzuhqwgFSo1UZq5RobUpcpINS3Zc0HmaqUvbKfU+riz1UwOiet9pwXpwf8GTMS7jvSzuq/8Mwl7a056yrofqKS8AT3Src9W3JhFXCPn/HaXi+OxHjsMJChTpriGjejwYD+kil7Zj7Pgzo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k29cbhWS; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A0DBC433C7; Tue, 6 Feb 2024 12:53:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707223984; bh=cC1iXIgYkNIh5eG5Gpxr3dx4+vBY/05hPu9acNFeElM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=k29cbhWS6DbbBWvLmOXATqMie993iIw7OOhgB8O5SsDgRv3ETZ4OtgZcTRGtsMfJY k4Q6fs2XLxOgjiqAZ1OJzIiEcRkSDl9qG14xeiNqdrvHyfqRuPCZSxo9WQBzcr0fxN l8TC75xfxnkM/CUq78l/VxHkL9mpbP6ssBEDxYwBo8VJfcyicwrdx4LEw15gJQJg1t 4ZbUGoMqX+lbqMwBtMZMVDsmOreSYjt79mpUlrR9Sru2vJE3dt0kVue52lmdHA/wQo u7FO8tpmVYPMk+4Vg5DyxSaZaaHQUjOmr/j5v5FZ/I8rCGtYZjJcmabuMVVuwCxvQg oD6vDVz1d0OdA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rXKwg-000obR-Ab; Tue, 06 Feb 2024 12:53:02 +0000 Date: Tue, 06 Feb 2024 12:53:01 +0000 Message-ID: <86v87169g2.wl-maz@kernel.org> From: Marc Zyngier To: Jon Hunter Cc: Sumit Gupta , treding@nvidia.com, krzysztof.kozlowski@linaro.org, mark.rutland@arm.com, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, amhetre@nvidia.com, bbasu@nvidia.com Subject: Re: [Patch] memory: tegra: Skip SID override from Guest VM In-Reply-To: <252d6094-b2d6-496d-b28f-93507a193ede@nvidia.com> References: <20240206114852.8472-1-sumitg@nvidia.com> <86wmrh6b2n.wl-maz@kernel.org> <252d6094-b2d6-496d-b28f-93507a193ede@nvidia.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: jonathanh@nvidia.com, sumitg@nvidia.com, treding@nvidia.com, krzysztof.kozlowski@linaro.org, mark.rutland@arm.com, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, amhetre@nvidia.com, bbasu@nvidia.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Hi Jon, On Tue, 06 Feb 2024 12:28:27 +0000, Jon Hunter wrote: > > Hi Marc, > > On 06/02/2024 12:17, Marc Zyngier wrote: > > Hi Sumit, > > > > On Tue, 06 Feb 2024 11:48:52 +0000, > > Sumit Gupta wrote: > >> > >> MC SID register access is restricted for Guest VM. > >> So, skip the SID override programming from the Guest VM. > >> > >> Signed-off-by: Sumit Gupta > >> --- > >> drivers/memory/tegra/tegra186.c | 11 +++++++++++ > >> 1 file changed, 11 insertions(+) > >> > >> diff --git a/drivers/memory/tegra/tegra186.c b/drivers/memory/tegra/tegra186.c > >> index 1b3183951bfe..df441896b69d 100644 > >> --- a/drivers/memory/tegra/tegra186.c > >> +++ b/drivers/memory/tegra/tegra186.c > >> @@ -10,6 +10,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> #include > >> @@ -118,6 +119,11 @@ static int tegra186_mc_probe_device(struct > >> tegra_mc *mc, struct device *dev) > >> unsigned int i, index = 0; > >> u32 sid; > >> + if (!is_kernel_in_hyp_mode()) { > >> + dev_dbg(mc->dev, "Register access not allowed\n"); > >> + return 0; > >> + } > >> + > >> if (!tegra_dev_iommu_get_stream_id(dev, &sid)) > >> return 0; > >> @@ -146,6 +152,11 @@ static int tegra186_mc_resume(struct > >> tegra_mc *mc) > >> #if IS_ENABLED(CONFIG_IOMMU_API) > >> unsigned int i; > >> + if (!is_kernel_in_hyp_mode()) { > >> + dev_dbg(mc->dev, "Register access not allowed\n"); > >> + return 0; > >> + } > >> + > >> for (i = 0; i < mc->soc->num_clients; i++) { > >> const struct tegra_mc_client *client = &mc->soc->clients[i]; > >> > > > > This doesn't look right. Multiple reasons: > > > > - This helper really has nothing to do in a driver. This is > > architectural stuff that is not intended for use outside of arch > > core code. > > We see a few other drivers using this ... > > drivers/perf/arm_pmuv3.c > drivers/clocksource/arm_arch_timer.c These two are definitely part of the CPU architecture. > drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h This is just a bug. Please don't copy this stuff. > drivers/hwtracing/coresight/coresight-etm4x-core.c > drivers/hwtracing/coresight/coresight-etm4x-core.c > drivers/irqchip/irq-apple-aic.c These are also part of the CPU architecture. > > We were looking for a way to determine if the OS is a guest OS or > not. However, I can see that this is a ARM64 specific API and so > probably the above are only compiled for ARM64. Interestingly, the AMD > driver implements the following ... > > static inline bool is_virtual_machine(void) > { > #if defined(CONFIG_X86) > return boot_cpu_has(X86_FEATURE_HYPERVISOR); > #elif defined(CONFIG_ARM64) > return !is_kernel_in_hyp_mode(); > #else > return false; > #endif > } This stuff should simply be ripped out and burned. Whoever wrote it didn't understand how this works. > > > - My own tegra186 HW doesn't have VHE, since it is ARMv8.0, and this > > helper will always return 'false'. How could this result in > > something that still works? Can I get a free CPU upgrade? > > I thought this API just checks to see if we are in EL2? It does. And that's the problem. On ARMv8.0, we run the Linux kernel at EL1. Tegra186 is ARMv8.0 (Denver + A57). So as written, this change breaks the very platform it intends to support. > > > - If you assign this device to a VM and that the hypervisor doesn't > > correctly virtualise it, then it is a different device and you > > should simply advertise it something else. Or even better, fix your > > hypervisor. > > Sumit can add some more details on why we don't completely disable the > device for guest OSs. It's not about disabling it. It is about correctly supporting it (providing full emulation for it), or advertising it as something different so that SW can handle it differently. Poking into the internals of how the kernel is booted for a driver that isn't tied to the core architecture (because it would need to access system registers, for example) is not an acceptable outcome. Thanks, M. -- Without deviation from the norm, progress is not possible.