From patchwork Tue Nov 29 19:19:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 27438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp524883wrr; Tue, 29 Nov 2022 11:22:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf7oSWj03xCFU+iL521RqTKr/C3zrwUhC1fCu+kThyR+whV40TdUZjrXwiqcuYFPXNrckf12 X-Received: by 2002:a17:906:30c1:b0:7b7:eaa9:c1cb with SMTP id b1-20020a17090630c100b007b7eaa9c1cbmr34699046ejb.745.1669749774086; Tue, 29 Nov 2022 11:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669749774; cv=none; d=google.com; s=arc-20160816; b=YNFqPvKLQpKF6ezwA+SkKDTyAbLIA8oq10C3LIiZTEi1MvhGlxwf9q9WKUsGWL24uP J1CXmZIrmHJjAudjbJgC7OkGAZhTUdoJbrFg13HVTkMr85Ed7GNxfrXnDX2EUETGG358 DFQdNVvH9wjMbQHaWW5qc/ugzG19jkjo8Dqyc8nWhSm2LFxSspk2eZnrcUO3kIR56Bi6 hpF4xaHJbatNvsGBDw8AnSJTtzgw4JYLuESBgFBaO8/ZvDZVZdZTN+3faLshM9ez09eu ecOARc2SxZ4k1znE7ha1qkZNtIxDunnlSjhzAEm0y9+aNY0i006AmM1aZrtKfJ/WSt7K N80Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LAtIXRb0PxV3UcO4TbJwOQlCaH/bLzgHLa5c6EYoqNs=; b=rirDbUDyrNpUmW9qs9TAaQnSoDpVIEd1ZJBmPQ6IMMqKrhKV7lLYXT876+jdNO3aNy Ps3WAYzb3NxPSLu0bY4mdBnZWSMqsUHxvd0f+6S4pF6bIIrGmqcKgvieNUjRFKcaIO7v bIHJoFNL5hlseqi0qvCcKmOGM51H1yhO7H4AoFg10YfCJHAM27KdoEaBPQKzdBxbMoOx cT0v5bohh65bOO/gmiO1/wCheyQ2A7DpnPTiQErhwlBlXZI9cxSHjJ0o12IdzbjtSmb5 ZnS8zO1rsV1Mhj96NYyILW99Ql1KFjjxcjMHSfb+SezZYUy83qWUzDZlFJ2Rm1vqFX52 pihQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=trhLlHeG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a05640235ca00b0046aeca41c55si8537772edc.212.2022.11.29.11.22.28; Tue, 29 Nov 2022 11:22:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=trhLlHeG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236893AbiK2TV0 (ORCPT + 99 others); Tue, 29 Nov 2022 14:21:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236812AbiK2TUv (ORCPT ); Tue, 29 Nov 2022 14:20:51 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3DAC6D48F; Tue, 29 Nov 2022 11:19:58 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1669749597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LAtIXRb0PxV3UcO4TbJwOQlCaH/bLzgHLa5c6EYoqNs=; b=trhLlHeGTz/PmAoiA09w30q8K6SNnj0CmzpDhmRBg7tUGjLWpYvph7djOsZrwFb0DDpZjd GrOFF+Vpj2I+jmVU2b6vUUyiz1X6AdNx+RwQRy7Iq+wVnC/7WYjaBLfaifsaWR/fs8UaFo jU/Xs8zsAjfPx3e1g4ONEZ1v11gRIP4= From: Oliver Upton To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] KVM: arm64: Use KVM's pte type/helpers in handle_access_fault() Date: Tue, 29 Nov 2022 19:19:43 +0000 Message-Id: <20221129191946.1735662-2-oliver.upton@linux.dev> In-Reply-To: <20221129191946.1735662-1-oliver.upton@linux.dev> References: <20221129191946.1735662-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750859539025319777?= X-GMAIL-MSGID: =?utf-8?q?1750859539025319777?= Consistently use KVM's own pte types and helpers in handle_access_fault(). No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 5 +++++ arch/arm64/kvm/mmu.c | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 63f81b27a4e3..192f33b88dc1 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -71,6 +71,11 @@ static inline kvm_pte_t kvm_phys_to_pte(u64 pa) return pte; } +static inline kvm_pfn_t kvm_pte_to_pfn(kvm_pte_t pte) +{ + return __phys_to_pfn(kvm_pte_to_phys(pte)); +} + static inline u64 kvm_granule_shift(u32 level) { /* Assumes KVM_PGTABLE_MAX_LEVELS is 4 */ diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index a3c71b5172cd..886ad5ee767a 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1399,20 +1399,18 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, /* Resolve the access fault by making the page young again. */ static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) { - pte_t pte; - kvm_pte_t kpte; + kvm_pte_t pte; struct kvm_s2_mmu *mmu; trace_kvm_access_fault(fault_ipa); write_lock(&vcpu->kvm->mmu_lock); mmu = vcpu->arch.hw_mmu; - kpte = kvm_pgtable_stage2_mkyoung(mmu->pgt, fault_ipa); + pte = kvm_pgtable_stage2_mkyoung(mmu->pgt, fault_ipa); write_unlock(&vcpu->kvm->mmu_lock); - pte = __pte(kpte); - if (pte_valid(pte)) - kvm_set_pfn_accessed(pte_pfn(pte)); + if (kvm_pte_valid(pte)) + kvm_set_pfn_accessed(kvm_pte_to_pfn(pte)); } /** From patchwork Tue Nov 29 19:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 27439 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp525008wrr; Tue, 29 Nov 2022 11:23:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf4yGBInrK6gQgGY+ivZuFKuA4OD4REL6l8FVi80v89GCN+n41QD++goJ/AW1qBr9B93TFES X-Received: by 2002:a05:6402:1802:b0:461:72cb:e5d with SMTP id g2-20020a056402180200b0046172cb0e5dmr44659444edy.410.1669749792089; Tue, 29 Nov 2022 11:23:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669749792; cv=none; d=google.com; s=arc-20160816; b=GJamiKCY03PM5x9kFExIEV5RgkwoTxupJX7w9VTVBHJyYD1aPeS+jCGSvwY2LnCDFR tjipyDlk/bVPFiQhh5oKDEZtMl6NT8DVF4C1C0onSeQr/Stk2RvgiIouHXNXc5/zxAyH g63oYv8Vr5PbQP5h2lSwlfSEkBh9CTglI9CptDyPYjhRN6iQho9DbK/iaWBtQK8irhtr cEkpVwimQ1/SE+bWGD+QBVT2skpOWIvp0HPsXsyVZpv76f5V4ARxG4FZlCosrzXHsWqf NB+WntrZu/j/kUQNL0Bp6XlTeJDny3l8TJ6BpMr+3DlMK1UrxjeyzHv3Niu3H2XL0tFp SxKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gZ4zOeCGbv1gvItGbIIGPQNuQz+qC/NQiSdoYbMqOcA=; b=YUbr2rTIfknlGxcoyP3r0f//SVbqMyHFDdQV4Dle+BFjOkY27aWJcr3wIhrWxFzHZ4 XsNqEYqNiXDapatCr9SAUzVxGZd5kSG+vwG5Hw/ejEhkErjJs+wMnR/26hyoLUGSLQQf UGQdGzjyhbNq4He2+TsohqRKwxcgXGjilw3LestvvTnMdT8CZtVGBJ5Iu/NSn9kWQqir TxjKGIvrENMc2XDxMuvjTMO3EtVaEeFSo/QIjeKVoDml4se+TniCeuQu6LEjt/zWRLiz srzjuk6HnXZO+5Prr//d6btft9KyPKFHYYWhugzMd+CI6ynTlPXUen71zWPYm7ZjC/g5 eAXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ivgJME64; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr12-20020a170907720c00b007c093acadb0si895999ejc.508.2022.11.29.11.22.47; Tue, 29 Nov 2022 11:23:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ivgJME64; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236902AbiK2TVc (ORCPT + 99 others); Tue, 29 Nov 2022 14:21:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236815AbiK2TUv (ORCPT ); Tue, 29 Nov 2022 14:20:51 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 486FD6D48C; Tue, 29 Nov 2022 11:20:01 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1669749599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gZ4zOeCGbv1gvItGbIIGPQNuQz+qC/NQiSdoYbMqOcA=; b=ivgJME643G8i5ESEr5NCoBRxVONgW7xNcfo9eS52aTmAiibYNqYar1tSVUGNHBZlpVpKsW fZVLO+TVjMk1oxRvpreTbTajXlBarEJAum8hCMBQG4qntEG7Y43uEXKfviUFRYDfwDIrMV rRTPphdF0qeiMRSwSaQinxn6tNZH9jk= From: Oliver Upton To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] KVM: arm64: Don't serialize if the access flag isn't set Date: Tue, 29 Nov 2022 19:19:44 +0000 Message-Id: <20221129191946.1735662-3-oliver.upton@linux.dev> In-Reply-To: <20221129191946.1735662-1-oliver.upton@linux.dev> References: <20221129191946.1735662-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750859558048241282?= X-GMAIL-MSGID: =?utf-8?q?1750859558048241282?= Of course, if the PTE wasn't changed then there are absolutely no serialization requirements. Skip the DSB for an unsuccessful update to the access flag. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index b11cf2c618a6..9626f615d9b8 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1094,9 +1094,13 @@ int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size) kvm_pte_t kvm_pgtable_stage2_mkyoung(struct kvm_pgtable *pgt, u64 addr) { kvm_pte_t pte = 0; - stage2_update_leaf_attrs(pgt, addr, 1, KVM_PTE_LEAF_ATTR_LO_S2_AF, 0, - &pte, NULL, 0); - dsb(ishst); + int ret; + + ret = stage2_update_leaf_attrs(pgt, addr, 1, KVM_PTE_LEAF_ATTR_LO_S2_AF, 0, + &pte, NULL, 0); + if (!ret) + dsb(ishst); + return pte; } From patchwork Tue Nov 29 19:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 27440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp525136wrr; Tue, 29 Nov 2022 11:23:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6CZ9Z1ne8CMarJs7Rnj8Cx6jLW0I1MFuPaMHoMsiPNSKQYHaYQthq8L5+Knw3Ziiicj7L5 X-Received: by 2002:a17:907:908d:b0:7be:fbc9:df5 with SMTP id ge13-20020a170907908d00b007befbc90df5mr11659891ejb.316.1669749809045; Tue, 29 Nov 2022 11:23:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669749809; cv=none; d=google.com; s=arc-20160816; b=X+ZcgNVO9reV/Gohu8Bsh3VztpeeqySVPBW85B2zqfUxJSZWk4tdXL6aIxRaYNwpIW MoWAQS3I8TmaSvHkJQHONjzdunVXiSDiHhWqFTNZGms6RX8mWCTbhOLPfTFqN61X6+lP yr3JQbYoR0uIKplidpErhoZ2OD+R/+P6AmfBsdB1jla5twKPZKGfH88mAPeVgp6WDcE9 1pWL2trMPLVC+RyjT0X3xQ8P7bPxpwYC0KmRZgOrPfh1xKF0sNUstKVB4DE3f70ghY0m uBxr7AR3LW8nzFqBb4+WGD13kFFm1gs4C3vK0FoCJXs5G+DlQxCTqbfUUPm7He6qdaVp NwnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kcCcdEvvwNGIdQ75NLzM3W5ItGtWtDkpHRzsetWKNGE=; b=iFSesaAdHhC77u160TDOVCV9QC9L99jAi2D3cSCHUTZ15+phBtjYZkbmD9IFmwI+VU hkZRwY/q8Y9Awh5jlHOgOekHYw872So8y5H5GrayspZpWl1gL5TeDHGTT8aHCqd2XOUk MYR1MvjZ4MITmljuthpbOkTgQC4mIo0M0O/Y25P7uWJSv8YCXiz0l4GvxIkG+0FR+Pc2 UTyNfAjk0M22ycpHYhacS54TxWXWP4hU/CLRLV9gqPHiTelTnXmZZzYFZ21PNiLDhhFp APlnvrZz1jKHw+7FDiHd3Ur7oyQZ1zrMwWlk4t4UXib+1LD+8Pvc1hl1qa17l5x21qDR EpQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hxIfAAIn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq29-20020a1709073f1d00b007adef1dceffsi3713847ejc.677.2022.11.29.11.23.05; Tue, 29 Nov 2022 11:23:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hxIfAAIn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236904AbiK2TVh (ORCPT + 99 others); Tue, 29 Nov 2022 14:21:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236737AbiK2TUw (ORCPT ); Tue, 29 Nov 2022 14:20:52 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12AFF6B3BF; Tue, 29 Nov 2022 11:20:04 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1669749602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kcCcdEvvwNGIdQ75NLzM3W5ItGtWtDkpHRzsetWKNGE=; b=hxIfAAInTnpV80RJl1MOplU9B+F7wko1aZ0kXwoNfPeIZ7mLgQMPu/2k0UoJcp40WP/Rbd 2bDrV8+x6MOHHN9BWWHQ5tkBOIM2kbW4M6a6SKLfqI8MCQ80kj47HEfkIrGFCirYKQP9u7 OmDozB0QEQ52eFKqV6Kq+CasS6AhCOg= From: Oliver Upton To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] KVM: arm64: Handle access faults behind the read lock Date: Tue, 29 Nov 2022 19:19:45 +0000 Message-Id: <20221129191946.1735662-4-oliver.upton@linux.dev> In-Reply-To: <20221129191946.1735662-1-oliver.upton@linux.dev> References: <20221129191946.1735662-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750859575624417518?= X-GMAIL-MSGID: =?utf-8?q?1750859575624417518?= As the underlying software walkers are able to traverse and update stage-2 in parallel there is no need to serialize access faults. Only take the read lock when handling an access fault. Signed-off-by: Oliver Upton Reviewed-by: Ricardo Koller --- arch/arm64/kvm/hyp/pgtable.c | 2 +- arch/arm64/kvm/mmu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 9626f615d9b8..1a3dd9774707 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1097,7 +1097,7 @@ kvm_pte_t kvm_pgtable_stage2_mkyoung(struct kvm_pgtable *pgt, u64 addr) int ret; ret = stage2_update_leaf_attrs(pgt, addr, 1, KVM_PTE_LEAF_ATTR_LO_S2_AF, 0, - &pte, NULL, 0); + &pte, NULL, KVM_PGTABLE_WALK_SHARED); if (!ret) dsb(ishst); diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 886ad5ee767a..347985a56414 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1404,10 +1404,10 @@ static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) trace_kvm_access_fault(fault_ipa); - write_lock(&vcpu->kvm->mmu_lock); + read_lock(&vcpu->kvm->mmu_lock); mmu = vcpu->arch.hw_mmu; pte = kvm_pgtable_stage2_mkyoung(mmu->pgt, fault_ipa); - write_unlock(&vcpu->kvm->mmu_lock); + read_unlock(&vcpu->kvm->mmu_lock); if (kvm_pte_valid(pte)) kvm_set_pfn_accessed(kvm_pte_to_pfn(pte)); From patchwork Tue Nov 29 19:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 27441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp525317wrr; Tue, 29 Nov 2022 11:23:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf5t8gWL7ld8k3pA6xakHVSJbSvwwdhbtFVtrAf0mR0n6oaVZ2zhAEBLBwUSLXSHvFufdlmh X-Received: by 2002:a17:906:f896:b0:7bb:cdd8:94e7 with SMTP id lg22-20020a170906f89600b007bbcdd894e7mr21766112ejb.369.1669749836489; Tue, 29 Nov 2022 11:23:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669749836; cv=none; d=google.com; s=arc-20160816; b=FsjZU67K1bjRzpxxbdwA+3M8oZQsbak6In9mJA58QGWGXpyb7Pv9HWgGjQrVu4YqlN rZ0Jg/31EF1Gyu818ifUR756+1WGf8PtZfgFcCZa36jQ/ncQA6tss3n0plb8MXKIBm25 SWtzEfBXfbJ2UpOVwrHgBCn+Lei0YHejjNEtUT7i23sQyGRbRY18lxjqlSfy8A3/oqOT f/aH3JcR2KZtgB4uhkdeTD+4qYAJimfMYbFplz+4L230vynO4TpcwR3zho7061NwLmTK HS04ayuuJB9i7uCGg/Vd+kGkq6frH7hCjamDRz78LILkXmUYxI+zmhpi6+nXdRWXUgnw hI8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=laDyv7YUrXbfqGAwMagZdnkFS+VaAukLw7cc05haSWA=; b=CqOyFQH+/U1/3+UAIDU0I38mtW8VpJPAPQH65ufrZmWbMddqMO6IfE1RdZJlbObtJG z6W4XYAv1GqaL1+fSvMIG9fXrR+jH4ssbC208N+UY1UdtatUiZGj5GVeOZ42WWS/wsaZ JqsuclZi6N5MTA3cNpmWnHkyzs5G3ChKPiDNKdOjZBKRg+0o7G7gWN8JmvomZUJdelfA biQZdVP1DFFD5IGDEFd0Tu0rOJGM0YrHW0FWGSLxPP27ldyXQ40yQlpHEblv0EuC/CVH 4D240utRd0LoKkOkbUNpvgfPgoWHARVQryWygGyibuZ1ea7YWXBmQBdUTfHCKlJ4XDok q4rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UdwE2yD+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bc2-20020a056402204200b0045c7611d8ddsi11634933edb.179.2022.11.29.11.23.32; Tue, 29 Nov 2022 11:23:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UdwE2yD+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236801AbiK2TVk (ORCPT + 99 others); Tue, 29 Nov 2022 14:21:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236865AbiK2TU4 (ORCPT ); Tue, 29 Nov 2022 14:20:56 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE0756E544; Tue, 29 Nov 2022 11:20:06 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1669749605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=laDyv7YUrXbfqGAwMagZdnkFS+VaAukLw7cc05haSWA=; b=UdwE2yD+Xreg9YPfNtiPciJasEmnad33G1DHyWSBDA7LwaT7n3KiwnnNO9bOgfsuBoI54F tbwcE9gGmZR/9cDmZ4YCQnOunSbgBloPF44HFlAEaw3Wbv927EOOsrVHVQZJ6abGcSkfq1 IGTSDogzwposXRkOGXjkbNu+97c6p1U= From: Oliver Upton To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] KVM: arm64: Condition HW AF updates on config option Date: Tue, 29 Nov 2022 19:19:46 +0000 Message-Id: <20221129191946.1735662-5-oliver.upton@linux.dev> In-Reply-To: <20221129191946.1735662-1-oliver.upton@linux.dev> References: <20221129191946.1735662-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750859604514291982?= X-GMAIL-MSGID: =?utf-8?q?1750859604514291982?= As it currently stands, KVM makes use of FEAT_HAFDBS unconditionally. Use of the feature in the rest of the kernel is guarded by an associated Kconfig option. Align KVM with the rest of the kernel and only enable VTCR_HA when ARM64_HW_AFDBM is enabled. This can be helpful for testing changes to the stage-2 access fault path on Armv8.1+ implementations. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 1a3dd9774707..9c651b6d4092 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -584,12 +584,14 @@ u64 kvm_get_vtcr(u64 mmfr0, u64 mmfr1, u32 phys_shift) lvls = 2; vtcr |= VTCR_EL2_LVLS_TO_SL0(lvls); +#ifdef CONFIG_ARM64_HW_AFDBM /* * Enable the Hardware Access Flag management, unconditionally * on all CPUs. The features is RES0 on CPUs without the support * and must be ignored by the CPUs. */ vtcr |= VTCR_EL2_HA; +#endif /* CONFIG_ARM64_HW_AFDBM */ /* Set the vmid bits */ vtcr |= (get_vmid_bits(mmfr1) == 16) ?