Received: by 2002:a05:7412:d024:b0:f9:90c9:de9f with SMTP id bd36csp54440rdb; Wed, 20 Dec 2023 06:13:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqJfQ4t5kfgmURPb+vM+zgLPm3eC7ggoU1AAqZFPjwLnA1uJ8dAzOdKj6bA2tUn0kFSoLa X-Received: by 2002:a17:902:654a:b0:1d3:71df:e0a9 with SMTP id d10-20020a170902654a00b001d371dfe0a9mr5383325pln.87.1703081609342; Wed, 20 Dec 2023 06:13:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703081609; cv=none; d=google.com; s=arc-20160816; b=rwqcGp0l8iJpEllTOGMewD/6QYlmPiodZXxyRObCNaE55GVn+KejI9vnzAmlRs3r6m aZaxy3SSYZwLWK/ffGEOssqvhkESzutBrc4AwtIS110TF3RPw+uLELQJnw3dMLuShjuA d9+wuydJ2n0mGP9D2vlEggbphWH42pwmau1U/zt6lKPchH5u7Wdz3O3SgqLSTEan89js 0eUBQ5w2CeKIiSsUQoJdxXO6Ug8MqbgU4HfbdXr3dNl6KTt15QhxnWst9hDZtepIwwnc OZlFqrCA4YJKVif3vVWbIfaa6YMr0OUgDqLJ1YB1vgR2Aey0uUGMV1BiPVoFrSwXCtjb ejgA== ARC-Message-Signature: i=1; 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=gxJ1bFhL9KCQeSQVumKw94jpnFncaXwGbKMNhScnvHY=; fh=jM1IIVaorIi3bQQFHFmeG1ab0qQQClwVwTgnyhdOVfM=; b=YnaL2BoF5yUPkFRJCoCAEew9JvKwSgHg6z5oHwgdIrJxGUSnm/8/E7mWqrFE63R/fE pwRe2HTRWnCgNr2yvgI0o0b/F9X/jOAFq2atDYkow3/bCuJRkw6uz+AvyfmPpBC25/hf klczyaGYT/6dkiz5T48fwZnfnjW6dbo6py+tbM+cq92taKY1L8jZyGl7WvRGhBEXUTQA orSJgLv9tSMHLXoHSb6k25cgQ8e9Jr+Fs9f8Q6PfoGvHhxSe0tn93gZd5SA51u5N++bq zsAgwBjDPcg0tWTW9OwepaQizQJGHxG/EueinshtmStDBadXOyhX1V71CEQyEGuUbnwX vSgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kfFn5Dvb; spf=pass (google.com: domain of linux-kernel+bounces-7041-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7041-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m5-20020a170902db0500b001ce5b8081a5si3613129plx.382.2023.12.20.06.13.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:13:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7041-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kfFn5Dvb; spf=pass (google.com: domain of linux-kernel+bounces-7041-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7041-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8185DB243BD for ; Wed, 20 Dec 2023 14:12:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1829238F8D; Wed, 20 Dec 2023 14:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kfFn5Dvb" X-Original-To: linux-kernel@vger.kernel.org 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 473A938DDD; Wed, 20 Dec 2023 14:12:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEB7DC433C7; Wed, 20 Dec 2023 14:12:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703081535; bh=omuGEKL0AnBbS+fvO5aEEjVVdipBqKAYv93nwOJV9Ss=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kfFn5Dvbbrr6iPRuNItHtdv6Wg3PZAyXrr95xvGleIi39+oOv90e36Fw7E1LPRtrk YIPmh5cnnozM0+VqfHkzu0sxLR1qmEAGMcRahaLSd3fvG/HpUsohvAYXNUHHihIPuq wpz3UEBa/45OpzSRAdrVOgLrwVJAELez9l+J+jyKcY9k6nNPMWYp6Ysoegw8M0X/RP ig2hn1EO9RCfzUcoq0/LlX5UBTbAkRD5mD/6Tm5taU7mVRmI4KkzNm7SCpi1tWIIsI KuYSCRF9jMYHZq7o+z3SQPS3dNYSXGJzzIromkeLLnA+vUAZXDmH4Gg1FChTGR7hyg wUXs6tFD7treQ== Received: from [104.132.45.104] (helo=wait-a-minute.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 1rFxIz-005haC-Go; Wed, 20 Dec 2023 14:12:13 +0000 Date: Wed, 20 Dec 2023 14:12:12 +0000 Message-ID: <87wmt9t137.wl-maz@kernel.org> From: Marc Zyngier To: Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v4 1/3] kvm: arm64: introduce new flag for non-cacheable IO memory In-Reply-To: <20231218090719.22250-2-ankita@nvidia.com> References: <20231218090719.22250-1-ankita@nvidia.com> <20231218090719.22250-2-ankita@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/28.2 (x86_64-pc-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: 104.132.45.104 X-SA-Exim-Rcpt-To: ankita@nvidia.com, jgg@nvidia.com, oliver.upton@linux.dev, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, alex.williamson@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, ardb@kernel.org, akpm@linux-foundation.org, gshan@redhat.com, mochs@nvidia.com, lpieralisi@kernel.org, aniketa@nvidia.com, cjia@nvidia.com, kwankhede@nvidia.com, targupta@nvidia.com, vsethi@nvidia.com, acurrid@nvidia.com, apopple@nvidia.com, jhubbard@nvidia.com, danw@nvidia.com, linux-mm@kvack.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 18 Dec 2023 09:07:17 +0000, wrote: > > From: Ankit Agrawal > > For various reasons described in the cover letter, and primarily to Well, the cover letter does not end-up in the git tree, so you must put some actual information here. > allow VM get IO memory with NORMALNC properties, it is desired > to relax the KVM stage 2 device memory attributes from DEVICE_nGnRE > to NormalNC. So set S2 PTE for IO memory as NORMAL_NC. > > A Normal-NC flag is not present today. So add a new kvm_pgtable_prot > (KVM_PGTABLE_PROT_NORMAL_NC) flag for it, along with its > corresponding PTE value 0x5 (0b101) determined from [1]. > > Lastly, adapt the stage2 PTE property setter function > (stage2_set_prot_attr) to handle the NormalNC attribute. > > [1] section D8.5.5 of DDI0487J_a_a-profile_architecture_reference_manual.pdf > > Signed-off-by: Ankit Agrawal > Suggested-by: Jason Gunthorpe > Acked-by: Catalin Marinas > Tested-by: Ankit Agrawal > --- > arch/arm64/include/asm/kvm_pgtable.h | 2 ++ > arch/arm64/include/asm/memory.h | 2 ++ > arch/arm64/kvm/hyp/pgtable.c | 13 +++++++++++-- > 3 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > index cfdf40f734b1..19278dfe7978 100644 > --- a/arch/arm64/include/asm/kvm_pgtable.h > +++ b/arch/arm64/include/asm/kvm_pgtable.h > @@ -197,6 +197,7 @@ enum kvm_pgtable_stage2_flags { > * @KVM_PGTABLE_PROT_W: Write permission. > * @KVM_PGTABLE_PROT_R: Read permission. > * @KVM_PGTABLE_PROT_DEVICE: Device attributes. > + * @KVM_PGTABLE_PROT_NORMAL_NC: Normal noncacheable attributes. > * @KVM_PGTABLE_PROT_SW0: Software bit 0. > * @KVM_PGTABLE_PROT_SW1: Software bit 1. > * @KVM_PGTABLE_PROT_SW2: Software bit 2. > @@ -208,6 +209,7 @@ enum kvm_pgtable_prot { > KVM_PGTABLE_PROT_R = BIT(2), > > KVM_PGTABLE_PROT_DEVICE = BIT(3), > + KVM_PGTABLE_PROT_NORMAL_NC = BIT(4), > > KVM_PGTABLE_PROT_SW0 = BIT(55), > KVM_PGTABLE_PROT_SW1 = BIT(56), > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index fde4186cc387..c247e5f29d5a 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -147,6 +147,7 @@ > * Memory types for Stage-2 translation > */ > #define MT_S2_NORMAL 0xf > +#define MT_S2_NORMAL_NC 0x5 > #define MT_S2_DEVICE_nGnRE 0x1 > > /* > @@ -154,6 +155,7 @@ > * Stage-2 enforces Normal-WB and Device-nGnRE > */ > #define MT_S2_FWB_NORMAL 6 > +#define MT_S2_FWB_NORMAL_NC 5 > #define MT_S2_FWB_DEVICE_nGnRE 1 > > #ifdef CONFIG_ARM64_4K_PAGES > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index c651df904fe3..0fff079a0ef3 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -718,10 +718,19 @@ static int stage2_set_prot_attr(struct kvm_pgtable *pgt, enum kvm_pgtable_prot p > kvm_pte_t *ptep) > { > bool device = prot & KVM_PGTABLE_PROT_DEVICE; > - kvm_pte_t attr = device ? KVM_S2_MEMATTR(pgt, DEVICE_nGnRE) : > - KVM_S2_MEMATTR(pgt, NORMAL); > + bool normal_nc = prot & KVM_PGTABLE_PROT_NORMAL_NC; > + kvm_pte_t attr; > u32 sh = KVM_PTE_LEAF_ATTR_LO_S2_SH_IS; > > + WARN_ON_ONCE(device && normal_nc); > + > + if (device) > + attr = KVM_S2_MEMATTR(pgt, DEVICE_nGnRE); > + else if (normal_nc) > + attr = KVM_S2_MEMATTR(pgt, NORMAL_NC); > + else > + attr = KVM_S2_MEMATTR(pgt, NORMAL); > + This whole thing can be written a bit more elegantly: switch (prot & (KVM_PGTABLE_PROT_DEVICE | KVM_PGTABLE_PROT_NORMAL_NC)) { case 0: attr = KVM_S2_MEMATTR(pgt, NORMAL); break; case KVM_PGTABLE_PROT_DEVICE: if (prot & KVM_PGTABLE_PROT_X) return -EINVAL; attr = KVM_S2_MEMATTR(pgt, DEVICE_nGnRE); break; case KVM_PGTABLE_PROT_NORMAL_NC: attr = KVM_S2_MEMATTR(pgt, NORMAL_NC); break; default: WARN_ON_ONCE(1); } and you can get rid of all of the boolean crud. M. -- Without deviation from the norm, progress is not possible.