From patchwork Sun Feb 11 17:47:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13552549 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 9F661C4829B for ; Sun, 11 Feb 2024 17:48:14 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hi69BGJEP1jsQ5JGktKkSpQI0EQltzEnDkOWkcN93C8=; b=3ADRQ2kIdk28+z IVVmBpA2L92fU+qRLbPzh57+LFfYEPeLyEeugOl8bWy31nIq7wuoCZk3sDraZwthJGW2dnlkocHaQ vBr3Hsi3xRIALmlW6VNrzBtXr3Ua1CuHMjq8lK6p/ZqKjLK4/37KGIgcQ/Wvu0N40lzb94fBeZOOC vMSJoxZaYswzA5x2VAI2CERK2gtpgg0ZyCKHjDKmIuCcQYlclYcuybq5ouMgKfyBzDi0k/ueGtDUB 2/BAL86f44kynkCCFFlAykNXzZ9PPS4oz0v5b9G8T9sfMbaRswadUm2zCJTvWpq7xv4Gs1i7sLlW1 boB5Rr7t65Is2y+bRsUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZDvw-000000036IK-3UKd; Sun, 11 Feb 2024 17:48:04 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZDvs-000000036Ej-4AYB for linux-arm-kernel@lists.infradead.org; Sun, 11 Feb 2024 17:48:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nEzsiuYFjSP8N4G5X5fjz1Ur1/N3qfKNECA9J6NbAjHkvXT866wLPKgq2H8q78RRTPgX6YpoEbQ2Smdt3x8AutDP0rkzJ9HdCehhSxozXhxdF9cAtWdk0eBdp6zzFaGrfI5pP8QiyYWmve6llN4raPYPFNMB+kf2hm4LzyBFGIC0+FQ4V4Ixw3kc1oi816xn1FN0bYw2gbYK3GmIH2OzXnQSAKBSpKob/en3wADXGrKxRDzydshvN1JSN8nU6r8xUMPTumzQ1bjo+aqfV+74367fOOwinLIytojx7Z2AqK9/EgJitvjN1HQ5OkUUonr7zPC5OSXM7GxxYet3rEeMhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GEUPBUp/mRSrwoBY6hHPxBFvFm1Cd4dE+qw16gP2bsw=; b=eiqQKPjOsGjX/jhWgG+ETYhHlcmVZdb2UEWHxnKF/UIHhrE3DwV95hYtUyI5qA0Gg4QlqxSMkaR49PYlS3S94obsy0OkvZh5dj60U0Z45FzDdfuNmDQCbtBMhIaJWecCdevVYn1lHQhQLyTEJC3nWKTX/6tFOaa1DtoIoz1vbDaeEtXdFaqnw1cZNuSHs9m6YNK100jsIjpRPrzRRtz2awdmhqTXMpphgoL2gcA2WM7lMrJHtG9NXauE4JKj5pOqgN4qjS8JOy9upckSBzJabbE72jyOjwHK19fvNLsTJUM1KbDIsh6Im3+BIcZLDZC8J9jXrFMifgn1XbUQTgEyJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GEUPBUp/mRSrwoBY6hHPxBFvFm1Cd4dE+qw16gP2bsw=; b=EtCuoswotMWpcrle1XP1yr9Eku3RnAE5vjr5yOJiRtAATzvKfW5tJ7FTL2sCnsys6TxFrMmATmyEbs8T6ai7UauzENkDL6T2kE7jhaMY4uokHu/KS8/+kXq4LuU5WifJxa3hkqrKlnNDtkkOd4F3hX/46rXJp/8luql+6/t8vLxvn48kHE/vxBDBPaN+iH2JnOZObgfZSuM3gv1t+bzfAWWS4rUuaTVplWQWa3xTtgeyygtuabbmoNAZRop9h8Vfmue1+4RY91XcS1+ZpH0cW7C7eUT+CxP3DdNFlytLzJwI7Hql68XsWubSjHMGMI+5jk0U4wGu5xPGSCprPiYv5A== Received: from DM6PR03CA0054.namprd03.prod.outlook.com (2603:10b6:5:100::31) by SN7PR12MB7225.namprd12.prod.outlook.com (2603:10b6:806:2a8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.14; Sun, 11 Feb 2024 17:47:53 +0000 Received: from DS3PEPF000099D6.namprd04.prod.outlook.com (2603:10b6:5:100:cafe::81) by DM6PR03CA0054.outlook.office365.com (2603:10b6:5:100::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.35 via Frontend Transport; Sun, 11 Feb 2024 17:47:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DS3PEPF000099D6.mail.protection.outlook.com (10.167.17.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Sun, 11 Feb 2024 17:47:53 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 11 Feb 2024 09:47:53 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Sun, 11 Feb 2024 09:47:52 -0800 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12 via Frontend Transport; Sun, 11 Feb 2024 09:47:41 -0800 From: To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v7 3/4] kvm: arm64: set io memory s2 pte as normalnc for vfio pci device Date: Sun, 11 Feb 2024 23:17:04 +0530 Message-ID: <20240211174705.31992-4-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240211174705.31992-1-ankita@nvidia.com> References: <20240211174705.31992-1-ankita@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D6:EE_|SN7PR12MB7225:EE_ X-MS-Office365-Filtering-Correlation-Id: 9328e4e7-c2b8-4281-f93b-08dc2b2992e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AhSeR5BaxNzG0QKrNhr7kPTxSNWm9QP170YFV72q5ODiA4Y1hSL7BppZPD7U14QobLia8LrifmyWzg4OzDLz5p2XhefJqXX5rhz7HZq3TUh+h32imnfEgh3agJAPc8qcXl/UfRms7q/jR8EYl6cBjCdjxk3wfKDi7/cdU3ocw0To/6hlZXYs7mK8fMmqzv/kcJso1BGTxaF/DEoDv+MwxxGSsCbYyxkxsD3w8Alz/OLrcxwhuF0bVAlVmI0iQpQ+lUx58AMJ7JBlA5dk2V4Sr0Lo3LePXECONE0nj9/ZAhEu9XBsrRGcupE60UKh8g1g/i5FkmkypVW/J90tvUhvvZccZjewmCbgwRbKnjebqy3U3fwQLmWO+R6z0pKeHw/hVNptqHbuMEA6K8s9FviUZ5Kt9i7JdJlKAHsICvkXXcNwrbn0gcrQ+LRHOEkWp+2MpjNXVwAzg33sk4nD2pxL6UNSVOO1z2xKsBvoMRV8VmwDbB44uZAse1Red/dRlAKi7pKsNBJuO1IteA+9AsXunLMOOLcP8A9OdDpqv6cTtL8k7BR+jELYQur/x+LMqsureYsk2yGkM9HgjItcuPpJJJas02+YpHdMxzVqstdTDZ4R3b+paz2MqfNSdiqZEmoPw5btCR0Px5o6avPd6wAG+w== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(376002)(396003)(136003)(39860400002)(346002)(230922051799003)(451199024)(82310400011)(186009)(64100799003)(1800799012)(40470700004)(36840700001)(46966006)(36756003)(921011)(478600001)(5660300002)(7636003)(7416002)(41300700001)(70206006)(8676002)(7696005)(1076003)(426003)(26005)(54906003)(2616005)(83380400001)(356005)(2876002)(336012)(2906002)(4326008)(110136005)(6666004)(86362001)(7406005)(70586007)(316002)(8936002)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2024 17:47:53.7134 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9328e4e7-c2b8-4281-f93b-08dc2b2992e9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D6.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7225 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240211_094801_111520_075F3CAC X-CRM114-Status: GOOD ( 15.36 ) 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 From: Ankit Agrawal To provide VM with the ability to get device IO memory with NormalNC property, map device MMIO in KVM for ARM64 at stage2 as NormalNC. Having NormalNC S2 default puts guests in control (based on [1], "Combining stage 1 and stage 2 memory type attributes") of device MMIO regions memory mappings. The rules are summarized below: ([(S1) - stage1], [(S2) - stage 2]) S1 | S2 | Result NORMAL-WB | NORMAL-NC | NORMAL-NC NORMAL-WT | NORMAL-NC | NORMAL-NC NORMAL-NC | NORMAL-NC | NORMAL-NC DEVICE | NORMAL-NC | DEVICE Still this cannot be generalized to non PCI devices such as GICv2. There is insufficient information and uncertainity in the behavior of non PCI driver. A driver must indicate support using the new flag VM_ALLOW_ANY_UNCACHED. Adapt KVM to make use of the flag VM_ALLOW_ANY_UNCACHED as indicator to activate the S2 setting to NormalNc. [1] section D8.5.5 of DDI0487J_a_a-profile_architecture_reference_manual.pdf Suggested-by: Catalin Marinas Acked-by: Jason Gunthorpe Reviewed-by: Catalin Marinas Signed-off-by: Ankit Agrawal --- arch/arm64/kvm/mmu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index d14504821b79..1742fdccb432 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1381,7 +1381,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, int ret = 0; bool write_fault, writable, force_pte = false; bool exec_fault, mte_allowed; - bool device = false; + bool device = false, vfio_allow_any_uc = false; unsigned long mmu_seq; struct kvm *kvm = vcpu->kvm; struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; @@ -1472,6 +1472,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, gfn = fault_ipa >> PAGE_SHIFT; mte_allowed = kvm_vma_mte_allowed(vma); + vfio_allow_any_uc = vma->vm_flags & VM_ALLOW_ANY_UNCACHED; + /* Don't use the VMA after the unlock -- it may have vanished */ vma = NULL; @@ -1557,10 +1559,14 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, if (exec_fault) prot |= KVM_PGTABLE_PROT_X; - if (device) - prot |= KVM_PGTABLE_PROT_DEVICE; - else if (cpus_have_final_cap(ARM64_HAS_CACHE_DIC)) + if (device) { + if (vfio_allow_any_uc) + prot |= KVM_PGTABLE_PROT_NORMAL_NC; + else + prot |= KVM_PGTABLE_PROT_DEVICE; + } else if (cpus_have_final_cap(ARM64_HAS_CACHE_DIC)) { prot |= KVM_PGTABLE_PROT_X; + } /* * Under the premise of getting a FSC_PERM fault, we just need to relax