From patchwork Tue Feb 20 15:10:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 203635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp465168dyc; Tue, 20 Feb 2024 07:12:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVLnzax4U7joxhLhR9QJZCRmeLM6iD2n3lYeVuMz3yvhafN+ikem62+02ryWCEkBjkOuGC6NX44CgwE6ShR4DnzBIBsqA== X-Google-Smtp-Source: AGHT+IGvg1Iu9eWAhfXczISjPKPkqJ3qI8I/ys61lTGZIPsPuKeqH3ie8C6RNSFf6K4p78KZ+dau X-Received: by 2002:a05:6871:587:b0:21e:6e02:2793 with SMTP id u7-20020a056871058700b0021e6e022793mr14008517oan.47.1708441944840; Tue, 20 Feb 2024 07:12:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708441944; cv=pass; d=google.com; s=arc-20160816; b=KolF7iCH/dWptr3UQjUw/N/+TZ7D00MJlxVOfkR2DhOr1Sns3Eillld6Gw0yWgBSdy MS08hZByA77GrsZkh+NmHcg6LE89yPZ33/v3zNQin5sdy6h9sVYP78AirSM4LLfGQEG2 JSy92P7UPaWmkVV8KO5KrehgN+jJPjz9jD2H5LbZAp1ooCWqtbttQoqsaVhRg15TN/0E /liIqmgOuJOMDcr8XlRYHjOEV8nP+gWInxs7r1N0HtrUnFqgvdexl71jFNYx/Accuewu EeEVo9j0TsQkuDZUXEuDUTHalWhDsGzc6vhydXmwJTegXODAhCArn6DL6YTBJTsKObvd 9x/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=Cjfo7uNgJv27FUK5l6GgvtACWLoTbWUGGoRS4ldTMrk=; fh=FwPJPLIV2tQZHRJ7/7pBTGUo8J86BL0741Gogk0i5R4=; b=IJdSLUDLr4HT+vXMjjgxZS88PvUkaSkSzfTXFmGIsBdlR80bcFVgv1HD+k7CkV6eUz bTqwdOE1FGsj3S0c8o+SfcA6II0jQgCoLoiy/3qIkY3G+JmoV+5RGQSHTlJ0ycjtlt4p Z8dHnCAsSJkQRB4E+XJQt1npmcDI/VYSKOCaJdRSp/jJcvzYLyplJQibblvtPbtUAVo3 SCwcXJrB1JXw452G390cb7Wx8zg8475vT3W7DxvREegf5G+dbDjijqTEm1qgivhmYowr WAce8I4k2HUx4wVZIDe0QOU9febm0YCTGd28KozPTkps+V2Qqteqp2CTuX7OPmrY5dQk PSzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xCceIkUA; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73222-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73222-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x27-20020a056a00189b00b006e46560c72bsi3276081pfh.87.2024.02.20.07.12.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:12:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73222-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xCceIkUA; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73222-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73222-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9AB3F281954 for ; Tue, 20 Feb 2024 15:12:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61737762D9; Tue, 20 Feb 2024 15:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xCceIkUA" Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E07F76036 for ; Tue, 20 Feb 2024 15:11:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441898; cv=none; b=ixjJRw01Uq+P4n+r1tLOBEi59majBVlgrjxs1uzcVq/xPy00XMLXvlxEANUr4/p/LOvlApDVQ5IsYg7OMjeQdQcKp//CNB4SDzC+S5z9fpVzIUVVBaG0hnlvfSWhLvVbKYS08G/kLo07bbo4ttJYeOwEFxFOfifQRRX4CiytwK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441898; c=relaxed/simple; bh=tK68vHtvU4jfzgwQpLeiCDjQItafC4TSz2LntPJnZug=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=S28y0VoCqvj1mBwhXENO4QTQnTOHqMC1bgdEpEVlJiknWFXJQnUOWacjkCOEcI8fBIYzDeQy9FBw5fSnv5S0bxXVeYuzQk3Qd+DHHZ0tHa9MqaCfvD85UgjNUXp3iRVj27bK45Vmrbdq65OpEU47hNx+bVweb3+M22xUx/uoUmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xCceIkUA; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-410d0660929so27456705e9.0 for ; Tue, 20 Feb 2024 07:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708441895; x=1709046695; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Cjfo7uNgJv27FUK5l6GgvtACWLoTbWUGGoRS4ldTMrk=; b=xCceIkUA9JeqU90NpUgHNpyo4B6qCMTHusc5CGNhZi6/KQ3jaI92fsSyd0Y1E6wbIt vvlPXxlVueWeeLIyStnk8fvavnbkWmH4u2VXoj3bkyf9Sfx7Ejkjho06oOzRhyDVpLK6 nZKgdIeX6TRbLfCuiI0MxGbv8L6b3k7c/DAvTRPFXxc8R2uPlWSMc03tbTVl8ZG2UVaV 4J5GK1206br8lobMbaAL0nWi/WG3oYRhHYpIBF5jcrpNOXtSolAk7KFwQY7nsEyODZAP FSpdiq9hz7GT5eqn+EgtxZnmcnEk04vMG2IB//diGAsI5laySsnitqTKLEkDTU93oY3S 6bxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708441895; x=1709046695; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Cjfo7uNgJv27FUK5l6GgvtACWLoTbWUGGoRS4ldTMrk=; b=ADRhfVh1PO76vrAl1UBZuL594K19+Lb20bXMfPfc5iyePMoelQN2avfGIqCy5roBJF AdQQxVlkHCD9zOEbGMz9JBFfnUXREzEVTVluVo6ES9f5gokdgb/aZ97e4OaZ9Xdgw5pA WtC/A4AmX4V6m6YsfbmQivg0ga4KIbYLJ89DMv987jXYJDF19rIVUuZRKKFTXkeF67fK Z9IJtrInU1Sr+Le5NyCG+1xAi1lX0Ne6RpwFPmqENX2TocEbxP72t/VB46CjobYkRtGl EzqiudWXXbcwtzLlbKjVaN2F7ANzSxsTAzekzcie/NUz/13muhQ0bHPj/8cJHoPM/IQg fNhg== X-Forwarded-Encrypted: i=1; AJvYcCX9wI3V5n2uirt2J+gChrIzuK/ZL/CcRw2uxsPjJTI5vWOW3qjY9uf3GTsn2NxBIJHQFrJv58h0DfFiSE7X2nbD1nl73AlgNqrEZjH7 X-Gm-Message-State: AOJu0YzhHT0e3IbETFToyQTS3f2QQn3hgNFGCLmFQ3fM7Cx6sOTEIvOL Xbm/0zOqSYev8LjSm6Rri/g++BfhHRP5kE6uc8wifeXUf4tWtXcQw00Ou2QpS2pZHGKAEIMVFV1 iWNI6nWA88aq9VELtxnK1lO9ZVg== X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:600c:a3a1:b0:410:e4fe:1a1f with SMTP id hn33-20020a05600ca3a100b00410e4fe1a1fmr157148wmb.0.1708441894686; Tue, 20 Feb 2024 07:11:34 -0800 (PST) Date: Tue, 20 Feb 2024 15:10:30 +0000 In-Reply-To: <20240220151035.327199-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240220151035.327199-1-sebastianene@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240220151035.327199-2-sebastianene@google.com> Subject: [PATCH v6 1/6] KVM: arm64: Move pagetable definitions to common header From: Sebastian Ene To: catalin.marinas@arm.com, gshan@redhat.com, james.morse@arm.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ricarkol@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, Sebastian Ene X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791431220639243253 X-GMAIL-MSGID: 1791431220639243253 In preparation for using the stage-2 definitions in ptdump, move some of these macros in the common header. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/kvm_pgtable.h | 42 ++++++++++++++++++++++++++++ arch/arm64/kvm/hyp/pgtable.c | 42 ---------------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index cfdf40f734b1..dd759e93084a 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -59,6 +59,48 @@ typedef u64 kvm_pte_t; #define KVM_PHYS_INVALID (-1ULL) +#define KVM_PTE_LEAF_ATTR_LO GENMASK(11, 2) + +#define KVM_PTE_LEAF_ATTR_LO_S1_ATTRIDX GENMASK(4, 2) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP GENMASK(7, 6) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RO \ + ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 2 : 3; }) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RW \ + ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 0 : 1; }) +#define KVM_PTE_LEAF_ATTR_LO_S1_SH GENMASK(9, 8) +#define KVM_PTE_LEAF_ATTR_LO_S1_SH_IS 3 +#define KVM_PTE_LEAF_ATTR_LO_S1_AF BIT(10) + +#define KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR GENMASK(5, 2) +#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R BIT(6) +#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W BIT(7) +#define KVM_PTE_LEAF_ATTR_LO_S2_SH GENMASK(9, 8) +#define KVM_PTE_LEAF_ATTR_LO_S2_SH_IS 3 +#define KVM_PTE_LEAF_ATTR_LO_S2_AF BIT(10) + +#define KVM_PTE_LEAF_ATTR_HI GENMASK(63, 50) + +#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55) + +#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54) + +#define KVM_PTE_LEAF_ATTR_HI_S2_XN BIT(54) + +#define KVM_PTE_LEAF_ATTR_HI_S1_GP BIT(50) + +#define KVM_PTE_LEAF_ATTR_S2_PERMS (KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \ + KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \ + KVM_PTE_LEAF_ATTR_HI_S2_XN) + +#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) +#define KVM_MAX_OWNER_ID 1 + +/* + * Used to indicate a pte for which a 'break-before-make' sequence is in + * progress. + */ +#define KVM_INVALID_PTE_LOCKED BIT(10) + static inline bool kvm_pte_valid(kvm_pte_t pte) { return pte & KVM_PTE_VALID; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index ab9d05fcf98b..eb83c8464b36 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -17,48 +17,6 @@ #define KVM_PTE_TYPE_PAGE 1 #define KVM_PTE_TYPE_TABLE 1 -#define KVM_PTE_LEAF_ATTR_LO GENMASK(11, 2) - -#define KVM_PTE_LEAF_ATTR_LO_S1_ATTRIDX GENMASK(4, 2) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP GENMASK(7, 6) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RO \ - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 2 : 3; }) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RW \ - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 0 : 1; }) -#define KVM_PTE_LEAF_ATTR_LO_S1_SH GENMASK(9, 8) -#define KVM_PTE_LEAF_ATTR_LO_S1_SH_IS 3 -#define KVM_PTE_LEAF_ATTR_LO_S1_AF BIT(10) - -#define KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR GENMASK(5, 2) -#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R BIT(6) -#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W BIT(7) -#define KVM_PTE_LEAF_ATTR_LO_S2_SH GENMASK(9, 8) -#define KVM_PTE_LEAF_ATTR_LO_S2_SH_IS 3 -#define KVM_PTE_LEAF_ATTR_LO_S2_AF BIT(10) - -#define KVM_PTE_LEAF_ATTR_HI GENMASK(63, 50) - -#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55) - -#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54) - -#define KVM_PTE_LEAF_ATTR_HI_S2_XN BIT(54) - -#define KVM_PTE_LEAF_ATTR_HI_S1_GP BIT(50) - -#define KVM_PTE_LEAF_ATTR_S2_PERMS (KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \ - KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \ - KVM_PTE_LEAF_ATTR_HI_S2_XN) - -#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) -#define KVM_MAX_OWNER_ID 1 - -/* - * Used to indicate a pte for which a 'break-before-make' sequence is in - * progress. - */ -#define KVM_INVALID_PTE_LOCKED BIT(10) - struct kvm_pgtable_walk_data { struct kvm_pgtable_walker *walker; From patchwork Tue Feb 20 15:10:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 203636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp465339dyc; Tue, 20 Feb 2024 07:12:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWIt+Tx7NRDPK4aeOCaXCk3oUX05ImhfkiVcFUtUa2QfsvOAffUsGCFGbfsPRxru+ka7cM9Sag0lDCxVAkTV/clsI0Djg== X-Google-Smtp-Source: AGHT+IEjEDQKQkf5/p1dRN9C0ai0OEFVuN1St0MYZTpQNtt6IrmvTbpKx4wWgv0pa0UmrRJKO7hy X-Received: by 2002:a05:6808:2e92:b0:3c1:5c06:7e99 with SMTP id gt18-20020a0568082e9200b003c15c067e99mr7279373oib.25.1708441960161; Tue, 20 Feb 2024 07:12:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708441960; cv=pass; d=google.com; s=arc-20160816; b=GVgcXbuFQ0nA03XbrOk9PQTdCsbQtdcKugLlAgZWOqTC40G5bvwOD3iQhDyDVUBlAD 2dUSBKw7X09h5V1vEDi+bO2WoxtaeGTlHcq2hvKvyHar+epUYpwoNPWnM0z+q2NP8L8U 3Mf44+skW//Np6O3rZP9Q9ysoOdz8FthwEZGP8fw07NdwN3yrzPa1uPdXxlTuWBMOUxB CoawegGlPjsQqMmJS5DQr0Pq0hQwmJsevmQUzORZduTxsag9E3W8rjpYyTXt4kyZKg33 LpHTqgTxeriTPbJn7ME/E+xyOG0ZNJGEVIjs5lff3WRcw6AR0AXl9bmqC1W8eX0YRmD7 aTAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=I0gsyti8lKhCK+AHvAHuyBhR7vYZPhP9z/P4jDBYvrE=; fh=GJqd/6Iz5mVURNv3BJUh7cjZ8tyBWD/BXj0zV8y4pfU=; b=VJVVO97K++WXz8UVfo6fw3SgDj+wihrO8k851dYVeCCzJz4l4Gdt+MnZc4XdEEsVe/ 9b20uuUOjWNzdUkw6mjkeiJMBVfgr0oteAUQjGA1W2+5tuLoh9HSA3nE/LKfZGcZZpYP /prNxIBlrADpomcmejkk9NFh5xt1R9tmg+en3n0Ry2kgrPjUalMijig02wHwsmfiSw81 AykY2x0tRuDa6Fcw/UT+TMdtFa9UqX6Bd0Oc/NuvsH1oILDpmJEIRbOutHo9gOHmCY4Y Y8yGMnVVwy7EIh/Ge+5ZMa2hD/ehB5+/SYrqW2HaO7M/qE+CUvwLjZd9ai/eZtmCVtlk ViGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rO9wEC1s; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73223-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73223-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vq1-20020a05620a558100b007873ae574aasi8900573qkn.240.2024.02.20.07.12.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:12:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73223-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rO9wEC1s; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73223-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73223-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 C1C321C20D14 for ; Tue, 20 Feb 2024 15:12:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE15D763E2; Tue, 20 Feb 2024 15:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rO9wEC1s" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EC3776042 for ; Tue, 20 Feb 2024 15:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441899; cv=none; b=G43yCCl9fI+oM5F6w+q88Fj+ik6EckIoftQNJ/Mq4ppq+sttHkFZJj3BxxVfkIYI06e/Qvduw/6iz0aG/8pPsf9bhBpksmICDVLL72mfeeElCfu95ZAmx9x5eYtNjsUqzMvjVuLyozLasJH4F73+IADR06dtlXD1LQdBHWFONzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441899; c=relaxed/simple; bh=NJa1BLuTC1M9IXyS8cUBmrPvfsMqCbFinRO8836TETA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mhtOPd5ka9VS+5uqKrlnx4lpt/3J1wWZyEIzScM05DXHlnBgTWtskQxe2QF7MwLyAB6GjkrZ6S6miBi78BZSeroq9nHZhhGqBJnM92M5REWZbZyxUQGCZjNsE6GXcpbAdcDuIvM1stSVCGni5P26H41SF2IrTTlrfexnUznck7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rO9wEC1s; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60810219282so33832377b3.0 for ; Tue, 20 Feb 2024 07:11:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708441897; x=1709046697; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I0gsyti8lKhCK+AHvAHuyBhR7vYZPhP9z/P4jDBYvrE=; b=rO9wEC1stMjKD+nC93Wopn4tp7d/GfLbZcL64kamuL+nXtFGG6xu09gUwZGOkfVub3 SM6PVwkUAcx5CxwgTnlArj67Omb3jQj6OK63++xXva4RgKd4dLl3fkygoL0d/W25Cno9 bhw6Y3ieKBJi8mBmRdK5SiF4sevZ7DCpy1s/9UOyTpUQtLFsZxdAz1zA369GUbev/rA0 u9+s2xarpbRTsusZC1Z+MLDt1tcLFMhjKVtey93fPC+5FIuqCQ+SySofOkfLxH41nlPy IZ+P1nThKRRITmujBCKx+y6OxEAxO7nUkRkFZmP9fozOdkEba3MwF+jWXGpBhXVc1OFp W1hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708441897; x=1709046697; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I0gsyti8lKhCK+AHvAHuyBhR7vYZPhP9z/P4jDBYvrE=; b=vQzgWRlsbc0KlgqCeXMiW+sqN1tcke3KsRt1inCGuEKtlRy+9kO4as9ZJ+ktwx8uSe ErkIVmYkK2Dw3oc5c6bsYyoJ6W4rvt+F6IOUT8idNjXJzdfPK1GTBl+2I2VBgEgj1g+S /CaDJUrK85GyarG6Ub2QneLGMQhLYl5K19Vrt6a21JF6rfXOga319dQv8O0/RdSMId36 OkMVSeOTzpB/hHUiJaUePFqysd3xxAZH0IMbfhkuGRCFTT3U87yWIC1RsNvRD30eFlup 7qyBa7J8tjkSgDuUSGYyd9ZSEVxdQcEWxrpmTgDr+7bwJkcp6e+TGONoyKdFHdCKNeee pxJw== X-Forwarded-Encrypted: i=1; AJvYcCURGlFqUiBp+H/45Ju6FCxcCAjKIV7b1Dp2512LwqjGnWQxxJrnDoF5ejvPvqZgujrppMe3RgIJndoPttG4slfaKtfwswS/cgjP+1z8 X-Gm-Message-State: AOJu0YxyaRuTpF4lSAJh/Bn3w1zjzdC11s9o7uuAtCXKZcR6yxlmpJpZ j4lNu0i6HQ/b6yxoeAbFHC25FaN3WtrqgfFrcvDPolQrKidDuDRqQPBpWyizchNE2jIB4+k7v2s Z6ecInHLyKkK8WoewSV2g3+nuyg== X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6902:1008:b0:dbe:a0c2:df25 with SMTP id w8-20020a056902100800b00dbea0c2df25mr871279ybt.8.1708441897282; Tue, 20 Feb 2024 07:11:37 -0800 (PST) Date: Tue, 20 Feb 2024 15:10:31 +0000 In-Reply-To: <20240220151035.327199-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240220151035.327199-1-sebastianene@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240220151035.327199-3-sebastianene@google.com> Subject: [PATCH v6 2/6] arm64: ptdump: Expose the attribute parsing functionality From: Sebastian Ene To: catalin.marinas@arm.com, gshan@redhat.com, james.morse@arm.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ricarkol@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, Sebastian Ene X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791431236789825832 X-GMAIL-MSGID: 1791431236789825832 To keep the same output format as the arch specific ptdump and for the sake of reusability, move the parser's state tracking code out of the arch specific. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 41 ++++++++++++++++++++++++++++++++- arch/arm64/mm/ptdump.c | 36 ++--------------------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 581caac525b0..23510be35084 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -9,6 +9,8 @@ #include #include +#include + struct addr_marker { unsigned long start_address; @@ -21,15 +23,52 @@ struct ptdump_info { unsigned long base_addr; }; +struct prot_bits { + u64 mask; + u64 val; + const char *set; + const char *clear; +}; + +struct pg_level { + const struct prot_bits *bits; + const char *name; + size_t num; + u64 mask; +}; + +/* + * The page dumper groups page table entries of the same type into a single + * description. It uses pg_state to track the range information while + * iterating over the pte entries. When the continuity is broken it then + * dumps out a description of the range. + */ +struct pg_state { + struct ptdump_state ptdump; + struct seq_file *seq; + const struct addr_marker *marker; + unsigned long start_address; + int level; + u64 current_prot; + bool check_wx; + unsigned long wx_pages; + unsigned long uxn_pages; +}; + void ptdump_walk(struct seq_file *s, struct ptdump_info *info); +void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, + u64 val); #ifdef CONFIG_PTDUMP_DEBUGFS #define EFI_RUNTIME_MAP_END DEFAULT_MAP_WINDOW_64 void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name); #else static inline void ptdump_debugfs_register(struct ptdump_info *info, const char *name) { } -#endif +#endif /* CONFIG_PTDUMP_DEBUGFS */ void ptdump_check_wx(void); +#else +static inline void note_page(void *pt_st, unsigned long addr, + int level, u64 val) { } #endif /* CONFIG_PTDUMP_CORE */ #ifdef CONFIG_DEBUG_WX diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index e305b6593c4e..64127c70b109 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -66,31 +66,6 @@ static struct addr_marker address_markers[] = { seq_printf(m, fmt); \ }) -/* - * The page dumper groups page table entries of the same type into a single - * description. It uses pg_state to track the range information while - * iterating over the pte entries. When the continuity is broken it then - * dumps out a description of the range. - */ -struct pg_state { - struct ptdump_state ptdump; - struct seq_file *seq; - const struct addr_marker *marker; - unsigned long start_address; - int level; - u64 current_prot; - bool check_wx; - unsigned long wx_pages; - unsigned long uxn_pages; -}; - -struct prot_bits { - u64 mask; - u64 val; - const char *set; - const char *clear; -}; - static const struct prot_bits pte_bits[] = { { .mask = PTE_VALID, @@ -170,13 +145,6 @@ static const struct prot_bits pte_bits[] = { } }; -struct pg_level { - const struct prot_bits *bits; - const char *name; - size_t num; - u64 mask; -}; - static struct pg_level pg_level[] = { { /* pgd */ .name = "PGD", @@ -248,8 +216,8 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr) st->wx_pages += (addr - st->start_address) / PAGE_SIZE; } -static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, - u64 val) +void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, + u64 val) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump); static const char units[] = "KMGTPE"; From patchwork Tue Feb 20 15:10:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 203637 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp465479dyc; Tue, 20 Feb 2024 07:12:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+6isvDGrGOtUDG8NfvaQRQpQq2SdgekD87terbS8dNiPqP1VyDQmjWrt9td12qD1k/XYuRrwrUPQATmOaibZ2mC/mBg== X-Google-Smtp-Source: AGHT+IE+2RZJ/KabkdA+4Ge649OY9UTPFU3ZbwnV+CWgh2fYWon0GLTFDf3/cu2xDueF8brhs7vs X-Received: by 2002:a05:6a00:1d1a:b0:6e4:6708:88eb with SMTP id a26-20020a056a001d1a00b006e4670888ebmr5947892pfx.31.1708441972085; Tue, 20 Feb 2024 07:12:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708441972; cv=pass; d=google.com; s=arc-20160816; b=ccaGZrJHfDl3TF0uaPi4Za8PddUk0di9+UQUfWPkMi2heVCAk8SZB48anwTCEC5JzK /t0O+enijIs/XFRajMSxt4+1mNYMBpmA6Mj9AoaJUt89eCYywHtBSXkK6MVQ6amKUC2K TDkGVd8PhHbR7GNDh4onZSsSYgG3BhkqVk+RzPZ2N76d0mmnrfVuNCClkahL1KaUKdtE Nn5K0d65gmlAEghU212odBeRsA+1TyXi2/W6SrctHoHw6eTR7+m18Iqm3S2guNOk4iv4 QSslgNkU/EyEMa2LWpeDcwDrwi6Fo6N6CAASzpb3gqg1WXJdoiU/fTCJ3D0C7blCZ7bE efvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=RNvbES0Rox8H1wht4HUzRcs5UM73wH2hWBF3+Zr3EJM=; fh=ld7xKphnlIoHivtvN1NjS6MVhCLE7O/us9xaz/G15PA=; b=yqJDPizKcnEZhAPz24GTPAvjQEVzGS957J2mpDBulphjQu2eCh+gO1ZwEeDhrPXizP rxeTxhnvzxM2iugnqEVQel3RQymeNBh6akW1az6rjurQ7T9yqjpT+xM1HKPHAoFE6I6J AzSvD/AcML0vusU9TFrv0g6F4XUBdm8YLPrJBO/SAGmRKozM+HqFgOodk+7DeeBIlUVH Jv8o3gMako5PAz/iC54SbtUegILCrt94anxvzTKVIKZOfJtAWngnsXZThvzWlylB2ZZD pYYTHjGGk27npa32J+TTaJc4fK3qY9b8hWLO1vIxfCU3uQUljPzf2MXz6LlQ9O952Osh FuHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=LxvNhJSv; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73224-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73224-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x27-20020a056a00189b00b006e46560c72bsi3276081pfh.87.2024.02.20.07.12.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:12:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73224-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=LxvNhJSv; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73224-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73224-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DB9C328194A for ; Tue, 20 Feb 2024 15:12:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7A20763F5; Tue, 20 Feb 2024 15:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LxvNhJSv" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AD96762C0 for ; Tue, 20 Feb 2024 15:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441901; cv=none; b=WukvU2HvbG4XGPjqcfpygZHd4uI01uyQIfbKwYqzsw+vjYuuXnWNcs5C6wnMuY23b4g7r5MiGD64zmjJwicgafZl8DqlhmdMKP0RT+opD9hEK+AIwMp2yb+yza8oHY52gi61afKUXLw4TKZNqPM2clJifbUz1smlJ3g/j0aTNp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441901; c=relaxed/simple; bh=IXOljfRlcheaKYN7knK3H0eeyYTrPTnwQOEMdeKsDl0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qJS4mDFUbYMlurLEsemkLu8xVku3BY7515qcbV0k2kjnw0jk9c9/vy5ofhPIFqCCcw2AqEkw/FqWuI1mhH+j11hu82BR74toFu5ApBD8MH+CP/+vz21ri8MqZTbkz3CAYLXO2jNnT83rej5pgLsGCplVCl9qxj2Cbv+wwJ4Qr+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LxvNhJSv; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60853aafd93so23086717b3.0 for ; Tue, 20 Feb 2024 07:11:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708441899; x=1709046699; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RNvbES0Rox8H1wht4HUzRcs5UM73wH2hWBF3+Zr3EJM=; b=LxvNhJSvCdbOAbRiGa2V1QJ+W8znDywkHUaSl5z6PdFGLwbnPODNpRsc+I9eSaDAsR pxkwkf15vtjdml1Vesshnlu+OsOLKPSn9MDXp6kz1ochuTGVBCrLzFP4MOTbD4Yv2ko3 T3moUrI3Vs1ObvrvmstJ0cSqQbvOP3+WncSdAKjEOI9Lii8+x65O+/+ofqkqNAzP+Psm qpygqW3JwgrCnhMH4JPw3His3PwDkeCN5w0vamgt12rkYE1px954Rg74q1zvZbYTzk0M fi1QxGZT688ZqDEZK/4qQc/gvG2+o/7pFglAiolisoDBYtVYwxRarG6h1s5ZoT+I9PmN S0kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708441899; x=1709046699; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RNvbES0Rox8H1wht4HUzRcs5UM73wH2hWBF3+Zr3EJM=; b=hPf5gBeQKb9l40iYLSJlW3fjRrhyEIA0wBv5Dh8PtHSQ/RpBaCaEiszIQtHkIR4Uxv L+FT36L2HYrvXmm3booCYa3brv3cE/3v27rAp/pJ2oeR+yCRZrK6Lg+ekeKPDIz44xZG MyvCFsYiCaUPe0eX0Vbw/SaE72LoEjHl/jFBDr1PUGNJxbK+F4u46S8s/7NiLOXq6HZ3 6Zy/nxDEr+wG3Rl7tp05dUifiTYeuVXHs6D2owmmEuW4yOWy4+VzBJ3mPIbn2WBSXCRw y0cpbUBSNc+abaAkgZV2VygKNMLAjeqmvnr2UAMa6EBoIh8kAJ2OMwapYDFLlkvqyWcu 9NNw== X-Forwarded-Encrypted: i=1; AJvYcCVz7YawZm54+1Iz4WzQymCh94tazT6Zz898Zysn6GBt/sZHoObe5MzAl22U7BUqnRVMFfoWykbUuYMskN7LqyfUtYNy33wmX9l2zbrd X-Gm-Message-State: AOJu0YxzTpR1v88yf80FTnUKy6BFXt+QWr9qIe/Lf42oFy2mFxKupIgy lbpt9GSWDD+TK2s7lhKNHmLac0b40G41V+ebVpe42hRZa2rfG+GjWFE5Xl4EcX3E49JYZldY9Vr yPvaexd7YkNXNsuGlPA2hKzhvuw== X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a25:d695:0:b0:dc7:7ce9:fb4d with SMTP id n143-20020a25d695000000b00dc77ce9fb4dmr4178814ybg.12.1708441899532; Tue, 20 Feb 2024 07:11:39 -0800 (PST) Date: Tue, 20 Feb 2024 15:10:32 +0000 In-Reply-To: <20240220151035.327199-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240220151035.327199-1-sebastianene@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240220151035.327199-4-sebastianene@google.com> Subject: [PATCH v6 3/6] arm64: ptdump: Use the mask from the state structure From: Sebastian Ene To: catalin.marinas@arm.com, gshan@redhat.com, james.morse@arm.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ricarkol@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, Sebastian Ene X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791431249200932673 X-GMAIL-MSGID: 1791431249200932673 Printing the descriptor attributes requires accessing a mask which has a different set of attributes for stage-2. In preparation for adding support for the stage-2 pagetables dumping, use the mask from the local context and not from the globally defined pg_level array. Store a pointer to the pg_level array in the ptdump state structure. This will allow us to extract the mask which is wrapped in the pg_level array and use it for descriptor parsing in the note_page. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 1 + arch/arm64/mm/ptdump.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 23510be35084..4e728d2a1f2c 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -45,6 +45,7 @@ struct pg_level { */ struct pg_state { struct ptdump_state ptdump; + struct pg_level *pg_level; struct seq_file *seq; const struct addr_marker *marker; unsigned long start_address; diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 64127c70b109..015ed65d3e9b 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -220,11 +220,12 @@ void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, u64 val) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump); + struct pg_level *pg_info = st->pg_level; static const char units[] = "KMGTPE"; u64 prot = 0; if (level >= 0) - prot = val & pg_level[level].mask; + prot = val & pg_info[level].mask; if (st->level == -1) { st->level = level; @@ -250,10 +251,10 @@ void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, unit++; } pt_dump_seq_printf(st->seq, "%9lu%c %s", delta, *unit, - pg_level[st->level].name); - if (st->current_prot && pg_level[st->level].bits) - dump_prot(st, pg_level[st->level].bits, - pg_level[st->level].num); + pg_info[st->level].name); + if (st->current_prot && pg_info[st->level].bits) + dump_prot(st, pg_info[st->level].bits, + pg_info[st->level].num); pt_dump_seq_puts(st->seq, "\n"); if (addr >= st->marker[1].start_address) { @@ -284,6 +285,7 @@ void ptdump_walk(struct seq_file *s, struct ptdump_info *info) st = (struct pg_state){ .seq = s, .marker = info->markers, + .pg_level = &pg_level[0], .level = -1, .ptdump = { .note_page = note_page, @@ -321,6 +323,7 @@ void ptdump_check_wx(void) { 0, NULL}, { -1, NULL}, }, + .pg_level = &pg_level[0], .level = -1, .check_wx = true, .ptdump = { From patchwork Tue Feb 20 15:10:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 203640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp467593dyc; Tue, 20 Feb 2024 07:15:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXLhYP6DSTaYIdqLw+vzu4kU6clmYnsy5GtLjFP2/qGj9lB30MxRQxbXNhjdSq7hzTo1pUWha39+Jf2/3+y0aL9Gv7vpg== X-Google-Smtp-Source: AGHT+IELu9mRN9K/4Qi8I+Z8PZGLiGKMMWngo0kK8yQtODc53Tjzq9QySS7AgjRV4hG41UiO0rls X-Received: by 2002:a05:6a00:228f:b0:6e4:7a32:aa22 with SMTP id f15-20020a056a00228f00b006e47a32aa22mr2426633pfe.20.1708442144822; Tue, 20 Feb 2024 07:15:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708442144; cv=pass; d=google.com; s=arc-20160816; b=Tf3Q0hgMOKNEFg9oTuU7NijwYgRaZUzAfC/Jdjq99zC9p+sSXQxSbcQABotdqYwdzS xXEk45qmTGun1525PSX8T8I965Dr8PttCzJE0pan0jTb++a6ANWKtGgA9F2S23zJDYwu 8ggnkbZqOESA0Ckn6BWPP+2laqeTioicmHGe1gXwg36of9Cyz5GVLDioofCwjWOtpPZB h2GPHtWUvXYS1ZZht+WAj4OMiZgyYHBAHwmanug4CsclUmGTZIfsNYAPVNDSsnul4Ppo XEpL6Mgw8jQiUKMiuAPtS6PqYLvhPh7oCVA9BKEa0UAs9u+fBQRGbBidQZIflMs9y0oU 30ug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=p126ZMPv5yWICgYljgBmVza3JvKiPG+UvgFwItLei+8=; fh=+ELE5T5nKVns0CpmHgc+07NTC3/4llFQS7tli2CyIjM=; b=N5eCA13ivNho4N7Olvtl34aNxES0uN6ZstpizrSNYJE21S1K1oh0dCpPy/HbFwm1lb mRg/EG6TOY5gp3LZukeeWlhYzfTSevcQN8m3vg9XDao6DHjLX+RtJIK9dWtfkl3qVPal A+mrc591G0Y2JB/+oysM7RFsm2SxKeUrwHnO9CWmgA5li9fqSKr6Sw9Iz/SRoSnTtEFJ trohGvqy3T9IyuSqWc469XiNB4ZiSUVnZZrTqJDzb/zpNdKsrUoXELe7xfQRxJ8d1uZq jAf8NyAcKWtzg8p/z+3FegaxXAQ6JmpXpavUJ/urn4VIkuKiXIICHlnjn4cn4bx6lXsQ ep/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tCyc6uBw; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73225-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bn20-20020a056a00325400b006e09499cc7bsi6307734pfb.269.2024.02.20.07.15.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:15:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tCyc6uBw; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73225-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 CE49FB22A09 for ; Tue, 20 Feb 2024 15:13:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7987768E4; Tue, 20 Feb 2024 15:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tCyc6uBw" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F36A762FB for ; Tue, 20 Feb 2024 15:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441905; cv=none; b=VRy0rpEFLAMkpdWO9dvvAM0FUYwaYINQj6apbXc99RYf2PsbC71UhOhhWVQ0uYNaBhU2PTLfgim6koVL6SeTxgf8JzAH/+TAMNdyU4B/SwRVm1y0XHBs+5CC0Jx/93ryMRU35F2Qqalc9U3VtZRFvJQH0AaQwCV00yD1hGj0Zeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441905; c=relaxed/simple; bh=jMavhYRCsq8TrG+5Wn0f9GwDD+Uua09tmUtXiDesIR8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T7DJ1Vksc33EnD2JPPLFQHMGSqeNbyVSG4UcVp/VMl0r/07V+RD/BWiWo4f/hIcdyNA6RkGqwY7Cll91J8YusVeWyM5FY7X+SvoVjQ9yxTHmfxorqhnZl0b2U17deKgeszZb/ArRyKwsju7SErG5fMksJgM+tY4BRoNjS14qNZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tCyc6uBw; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so4624610276.0 for ; Tue, 20 Feb 2024 07:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708441901; x=1709046701; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=p126ZMPv5yWICgYljgBmVza3JvKiPG+UvgFwItLei+8=; b=tCyc6uBwnGvwKjNwTw0Hfj/mbG6DKrsLL1b4mB+eKgEaJIqgWEivMdBOv6wNZBC3oE UwgQlCNPu6XLaxNwAfe9aZaeYxqT3JMW7AltVoAlGKq//DAqYKP7br7FRuZdJyPO0ajL turDEcTrDeypLwlOo6irez+M3tNctc173Ap3zDHYAQTb1n+zk55z2cFS0SLBikE39xeA FGSIiuQMkcd1g/eKxoQ+9lwLbXarsLoQqU7CCALoiJX4cC1wZ3VP1OzZU7k2M73d5pNn kP9X6Z1Xo0GkYijC+c4VywSgVEVYhtdRpzSBIU+MYlfp6/yXnh7oSr/EuRNrhPJEcOxr A8hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708441901; x=1709046701; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=p126ZMPv5yWICgYljgBmVza3JvKiPG+UvgFwItLei+8=; b=vS+79bJlSSy6kOWGbpyzj7MH90vDuKdTrsejklFk9RLY2lzrmB0QrC6EdaBID0IJLv Ot/xu2TAwSGrCVgTwKSMyvJx8SlfxhoN/+eLq+d4pRKsUO/noahDZOOA68uh+ehJKysS IEifgo88X/iLvQqccCAQG+QZ5Ya7jGVwY6UiwtBav1GCZ7EmfZUwS8XrkSyUGA1epUBG 1caomQvskGbAV+VVRVzGHH7YcBs3q5XRyr/mQeodrmkNI6fjgac7bAYj8cjmyQ2Iv0xK YUYyVk42iN6QrY8FOlZawu30ITdpaLiwm/pcz77EfngVUpB7w4fODIZdblGowScXdaDi GiMg== X-Forwarded-Encrypted: i=1; AJvYcCXzz3s4m/oLFWWTvYNkKDQENdnooV9PlGCGd1aTjXQAmrsx2FAcRy61p91IgQeldveT04RElaERtF5k2KJteZMzWeid3P03jJdT9Ym/ X-Gm-Message-State: AOJu0YxxDNgb1nW+Tar04eP9ZCtqXKfeqMgwGCY95ogSTuNB7cB4e0mN Jpk9z/8Svb2kG3EqBxzLWLYOtXjP2tCsWXdzwSUzeLDNhYPnV12ikPETGmV5arShwtLsefjw0LV q+qZSZiLDdm6N46P35pTINK6KuQ== X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6902:100a:b0:dc6:c94e:fb85 with SMTP id w10-20020a056902100a00b00dc6c94efb85mr573440ybt.2.1708441901684; Tue, 20 Feb 2024 07:11:41 -0800 (PST) Date: Tue, 20 Feb 2024 15:10:33 +0000 In-Reply-To: <20240220151035.327199-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240220151035.327199-1-sebastianene@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240220151035.327199-5-sebastianene@google.com> Subject: [PATCH v6 4/6] KVM: arm64: Register ptdump with debugfs on guest creation From: Sebastian Ene To: catalin.marinas@arm.com, gshan@redhat.com, james.morse@arm.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ricarkol@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, Sebastian Ene X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791431430397633484 X-GMAIL-MSGID: 1791431430397633484 While arch/*/mem/ptdump handles the kernel pagetable dumping code, introduce KVM/ptdump which shows the guest stage-2 pagetables. The separation is necessary because most of the definitions from the stage-2 pagetable reside in the KVM path and we will be invoking functionality **specific** to KVM. When a guest is created, register a new file entry under the guest debugfs dir which allows userspace to show the contents of the guest stage-2 pagetables when accessed. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/Kconfig | 13 ++++++ arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/debug.c | 8 ++++ arch/arm64/kvm/kvm_ptdump.h | 20 +++++++++ arch/arm64/kvm/ptdump.c | 88 +++++++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 arch/arm64/kvm/kvm_ptdump.h create mode 100644 arch/arm64/kvm/ptdump.c diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 27ca89b628a0..83ca07d16cf4 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -67,4 +67,17 @@ config PROTECTED_NVHE_STACKTRACE If unsure, or not using protected nVHE (pKVM), say N. +config PTDUMP_STAGE2_DEBUGFS + bool "Present the stage-2 pagetables to debugfs" + depends on PTDUMP_DEBUGFS && KVM + default n + help + Say Y here if you want to show the stage-2 kernel pagetables + layout in a debugfs file. This information is only useful for kernel developers + who are working in architecture specific areas of the kernel. + It is probably not a good idea to enable this feature in a production + kernel. + + If in doubt, say N. + endif # VIRTUALIZATION diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile index c0c050e53157..190eac17538c 100644 --- a/arch/arm64/kvm/Makefile +++ b/arch/arm64/kvm/Makefile @@ -23,6 +23,7 @@ kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \ vgic/vgic-its.o vgic/vgic-debug.o kvm-$(CONFIG_HW_PERF_EVENTS) += pmu-emul.o pmu.o +kvm-$(CONFIG_PTDUMP_STAGE2_DEBUGFS) += ptdump.o always-y := hyp_constants.h hyp-constants.s diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c index 8725291cb00a..ff97af2c0513 100644 --- a/arch/arm64/kvm/debug.c +++ b/arch/arm64/kvm/debug.c @@ -14,6 +14,8 @@ #include #include +#include + #include "trace.h" /* These are the bits of MDSCR_EL1 we may manipulate */ @@ -342,3 +344,9 @@ void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu) vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_SPE); vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_TRBE); } + +int kvm_arch_create_vm_debugfs(struct kvm *kvm) +{ + kvm_ptdump_guest_register(kvm); + return 0; +} diff --git a/arch/arm64/kvm/kvm_ptdump.h b/arch/arm64/kvm/kvm_ptdump.h new file mode 100644 index 000000000000..5e8a655605f1 --- /dev/null +++ b/arch/arm64/kvm/kvm_ptdump.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) Google, 2023 + * Author: Sebastian Ene + */ + +#ifndef __KVM_PTDUMP_H +#define __KVM_PTDUMP_H + +#include +#include + + +#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS +void kvm_ptdump_guest_register(struct kvm *kvm); +#else +static inline void kvm_ptdump_guest_register(struct kvm *kvm) {} +#endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */ + +#endif /* __KVM_PTDUMP_H */ diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c new file mode 100644 index 000000000000..9b04c24bb9be --- /dev/null +++ b/arch/arm64/kvm/ptdump.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Debug helper used to dump the stage-2 pagetables of the system and their + * associated permissions. + * + * Copyright (C) Google, 2023 + * Author: Sebastian Ene + */ +#include +#include +#include + +#include +#include + + +static int kvm_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx, + enum kvm_pgtable_walk_flags visit) +{ + struct pg_state *st = ctx->arg; + struct ptdump_state *pt_st = &st->ptdump; + + note_page(pt_st, ctx->addr, ctx->level, ctx->old); + return 0; +} + +static int kvm_ptdump_show_common(struct seq_file *m, + struct kvm_pgtable *pgtable, + struct pg_state *parser_state) +{ + struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) { + .cb = kvm_ptdump_visitor, + .arg = parser_state, + .flags = KVM_PGTABLE_WALK_LEAF, + }; + + return kvm_pgtable_walk(pgtable, 0, BIT(pgtable->ia_bits), &walker); +} + +static int kvm_ptdump_guest_show(struct seq_file *m, void *) +{ + struct kvm *kvm = m->private; + struct kvm_s2_mmu *mmu = &kvm->arch.mmu; + struct pg_state parser_state = {0}; + int ret; + + write_lock(&kvm->mmu_lock); + ret = kvm_ptdump_show_common(m, mmu->pgt, &parser_state); + write_unlock(&kvm->mmu_lock); + + return ret; +} + +static int kvm_ptdump_guest_open(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + int ret; + + if (!kvm_get_kvm_safe(kvm)) + return -ENOENT; + + ret = single_open(file, kvm_ptdump_guest_show, m->i_private); + if (ret < 0) + kvm_put_kvm(kvm); + + return ret; +} + +static int kvm_ptdump_guest_close(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + + kvm_put_kvm(kvm); + return single_release(m, file); +} + +static const struct file_operations kvm_ptdump_guest_fops = { + .open = kvm_ptdump_guest_open, + .read = seq_read, + .llseek = seq_lseek, + .release = kvm_ptdump_guest_close, +}; + +void kvm_ptdump_guest_register(struct kvm *kvm) +{ + debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry, + kvm, &kvm_ptdump_guest_fops); +} From patchwork Tue Feb 20 15:10:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 203638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp465913dyc; Tue, 20 Feb 2024 07:13:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUXGFIHyW9fb++jcHnv3GeWLSWwWtSliymx7uxquQTqM8JDVlbP3cs1AmMQrz6IQTfiurrjcnw38wURzBMcEeoYW1XvZg== X-Google-Smtp-Source: AGHT+IGnqTYzkgoJuY9Y4XQDdO+ay6m06kEzGirmh7TZTGdzmTmylvDe/IextfBqW9e1NkTiKrv1 X-Received: by 2002:a05:6402:17cc:b0:564:9019:f865 with SMTP id s12-20020a05640217cc00b005649019f865mr5064544edy.12.1708442009917; Tue, 20 Feb 2024 07:13:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708442009; cv=pass; d=google.com; s=arc-20160816; b=Mfus6Z0YiVWyCdhPV0mZzdEwONxG+LMPsvVlXnM5Dfr9dHjXPJWfRyECMVyROKbvnQ y771Fzid7fLH1BZ5yaMIcMkonLBu9d88ZMMn5EC204JiORclYEyHqXxg2YQb80/xGAr8 yOlgHwO7zkv5bOvexYUB0lrEk4T4XXvEF0Zp4MjnI05X4lZ9BUtPnTOhx4VhGt6fLBqG eOmxXaPRuGwOrWZqFhku/fe3bCDx8KKc0PjcqAEw5m79KmS3WKRsSduE9OD++dh94hER w48oFGX6utdpxvLEVn2myMtib2VRuiQo5dL2SoCEaw6wiXMGO6SKoALBufzzgx6s9K2a Nkmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=ZHfwmvLyQ0+qgqD3PE0n64rmEHSiFk4davoaQ8asvC8=; fh=Ffa9zuGqDmXz14IVUH9fIb0VBC6NurzcFeLwtQTm8TE=; b=vOauhQLiOR9TciLBBIZq9nZWQZg2a23hhCCbdmImymRl408ySAsRNXmYDeF22qP5s4 BLIDM5pjUVJmzTbnYHZY6urQLtzRWH8NaJwlLqHIYr/IFkGu48ci9HJaHXezxIzjFOCR U6I8ztlOuJW3JX3maxs+WxHnl1tc6POrtkDIDMU0+J0AzC5rof9hybAqrB1ma84/ReCJ 8lFdhMoyebooZbTfoI1GxpJGwa8Swimtm/WnfRSVeEdIUP5LHduvqiZ9XdDQ7ftfDI2+ IpxkaA+2ffo6xNpw9OBd8KEMT2jCLWCkavP5Y3Fap1zyMtN/bYa37qLs4SP13Ox3JciR tI5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Iqc5rFB4; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73226-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73226-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n20-20020a5099d4000000b00564566672b6si2335323edb.303.2024.02.20.07.13.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:13:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73226-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Iqc5rFB4; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73226-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73226-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 3431A1F22485 for ; Tue, 20 Feb 2024 15:13:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 548D074E0F; Tue, 20 Feb 2024 15:11:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Iqc5rFB4" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23251763FD for ; Tue, 20 Feb 2024 15:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441906; cv=none; b=IjbMFHcUsNFxKLQDDRpDYbOghCKkBDBHrTVgkCu9TeJ2fEx08d7w3lKbD1ljdQqeQLWvdJLn5RqkWhg/3tMYyJH6RszpzAvsIMLiy2zEOFTP1SpK1PpP3Zx+uyvMdiAEQtHb0vKtp8jZvPm5LmpSejYo0tRmEHUtOXwYkNwHzJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441906; c=relaxed/simple; bh=osQOTfWyBrFUVH8hZunBwsrwKsnogQjJ3uD+EhyAPM4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=G2iozxCoPsO+WcguAJTD5P8HRZC0vEj6ImOckFmtmhiZMCtvXhssgk5TK2mcmQjOdj+s+X4WVgdqYTZeOIp4siUbSMYHpFgcH/j62BEVKbiEFGGbZyTkP3RBxu9zxpw1QQzxPYYUH9/W8BR4IA9JY7J3Hx8kW1B2pmqRoKfAmdU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Iqc5rFB4; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6ceade361so10386963276.0 for ; Tue, 20 Feb 2024 07:11:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708441904; x=1709046704; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZHfwmvLyQ0+qgqD3PE0n64rmEHSiFk4davoaQ8asvC8=; b=Iqc5rFB4b6Ws5GRhffS4rw1vcOaJR8md+JEvWtXfqcpDh6OezG1stx2JUbsadkdU+O GZGzJWvtvFdpVLb2kyZGdJe7pz0UQjZaHoWMlEXr3W4tX1CPPHj11t4fT+x2000zyKvw u/H0dTDmzryxxMnPKttXvoASbgpponrp7U5WcKBeQJmMrA1uyvx3fyRsQG5DtF450rfF tdQLWZaC7aapxDTrheJQ6zXwgTcCW0w/spro6ktm07oP20G4amR7U/i51cfUSBsP52St xw8chp2dZW9O16a958TURA/SFFbrOOPvihBoVribsexTntxfzR9UWn/Sbz7vzDrz2Ldd RmLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708441904; x=1709046704; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZHfwmvLyQ0+qgqD3PE0n64rmEHSiFk4davoaQ8asvC8=; b=gynp/c24y60MF4trvx2wVzIImjffwDEAHYGtdIbe6u6Dd2k5ORsIBUu9iUuXuS1EOn HNbsZkahJUloozd6lUId6uwAskrpIMYhWSJueuZqgpB4PR+GvzEGKE/bocLDtPrxhyXr cRSm4h8CbovzIf+zwFzTCxx/WNJP5H48+gszlQWkEIDBEmNGvuTQY95mzlvB38OEXXLZ zwKxhfWVpG/YVjlqTcE+8oahTcN4Eavoe3wrnLqV7yArXe3C4zfmdMir4LZGLgw8EZ/3 RBR3A+Z3aIfNkCQ/X2It+8RWKFD4fNAds+kmdPdfKJTG4uWy5ffh0qGB4N+S4IA2KGd0 YKlQ== X-Forwarded-Encrypted: i=1; AJvYcCXHxbFpx340cq9v2aEL1+Ywky2joJTs4HGy472cDYClo/KAfb+vRKOa1YX00zwxQx4ob2IiUtdMtc9AYJvFtUti0msPJaZJw0lBF2Rr X-Gm-Message-State: AOJu0YxG97k3J2ZAWKJAXyGHyPqaoHag1utuR5bvLjvlR0PHZ53Aum3h YHjb7lY4pUpY9KmYB326PSBb6cIrEfcPms2O4JnqTAFYoEEDm1Fnob2SBGoC7Utnu+zgR0XkCqR +VUgZGg5REtPX70OtReBDV4X6tQ== X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a25:c78d:0:b0:dcd:ad52:6932 with SMTP id w135-20020a25c78d000000b00dcdad526932mr3864927ybe.5.1708441904161; Tue, 20 Feb 2024 07:11:44 -0800 (PST) Date: Tue, 20 Feb 2024 15:10:34 +0000 In-Reply-To: <20240220151035.327199-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240220151035.327199-1-sebastianene@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240220151035.327199-6-sebastianene@google.com> Subject: [PATCH v6 5/6] KVM: arm64: Initialize the ptdump parser with stage-2 attributes From: Sebastian Ene To: catalin.marinas@arm.com, gshan@redhat.com, james.morse@arm.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ricarkol@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, Sebastian Ene X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791431288676758760 X-GMAIL-MSGID: 1791431288676758760 Define a set of attributes used by the ptdump parser to display the properties of a guest memory region covered by a pagetable descriptor. Build a description of the pagetable levels and initialize the parser with this configuration. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/ptdump.c | 146 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 139 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index 9b04c24bb9be..2c4e0c122d23 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -14,6 +14,61 @@ #include +#define MARKERS_LEN (2) +#define KVM_PGTABLE_LEVELS (KVM_PGTABLE_LAST_LEVEL + 1) + +struct kvm_ptdump_guest_state { + struct kvm *kvm; + struct pg_state parser_state; + struct addr_marker ipa_marker[MARKERS_LEN]; + struct pg_level level[KVM_PGTABLE_LEVELS]; + struct ptdump_range range[MARKERS_LEN]; +}; + +static const struct prot_bits stage2_pte_bits[] = { + { + .mask = PTE_VALID, + .val = PTE_VALID, + .set = " ", + .clear = "F", + }, { + .mask = KVM_PTE_LEAF_ATTR_HI_S2_XN | PTE_VALID, + .val = KVM_PTE_LEAF_ATTR_HI_S2_XN | PTE_VALID, + .set = "XN", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | PTE_VALID, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | PTE_VALID, + .set = "R", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | PTE_VALID, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | PTE_VALID, + .set = "W", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_AF | PTE_VALID, + .val = KVM_PTE_LEAF_ATTR_LO_S2_AF | PTE_VALID, + .set = "AF", + .clear = " ", + }, { + .mask = PTE_NG, + .val = PTE_NG, + .set = "FnXS", + .clear = " ", + }, { + .mask = PTE_CONT | PTE_VALID, + .val = PTE_CONT | PTE_VALID, + .set = "CON", + .clear = " ", + }, { + .mask = PTE_TABLE_BIT, + .val = PTE_TABLE_BIT, + .set = " ", + .clear = "BLK", + }, +}; + static int kvm_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx, enum kvm_pgtable_walk_flags visit) { @@ -37,15 +92,78 @@ static int kvm_ptdump_show_common(struct seq_file *m, return kvm_pgtable_walk(pgtable, 0, BIT(pgtable->ia_bits), &walker); } +static int kvm_ptdump_build_levels(struct pg_level *level, u32 start_lvl) +{ + static const char * const level_names[] = {"PGD", "PUD", "PMD", "PTE"}; + u32 i = 0; + u64 mask = 0; + + if (start_lvl > 2) { + pr_err("invalid start_lvl %u\n", start_lvl); + return -EINVAL; + } + + for (i = 0; i < ARRAY_SIZE(stage2_pte_bits); i++) + mask |= stage2_pte_bits[i].mask; + + for (i = start_lvl; i <= KVM_PGTABLE_LAST_LEVEL; i++) { + level[i].name = level_names[i]; + level[i].num = ARRAY_SIZE(stage2_pte_bits); + level[i].bits = stage2_pte_bits; + level[i].mask = mask; + } + + if (start_lvl > 0) + level[start_lvl].name = level_names[0]; + + return 0; +} + +static struct kvm_ptdump_guest_state +*kvm_ptdump_parser_init(struct kvm *kvm) +{ + struct kvm_ptdump_guest_state *st; + struct kvm_s2_mmu *mmu = &kvm->arch.mmu; + struct kvm_pgtable *pgtable = mmu->pgt; + int ret; + + st = kzalloc(sizeof(struct kvm_ptdump_guest_state), GFP_KERNEL_ACCOUNT); + if (!st) + return NULL; + + ret = kvm_ptdump_build_levels(&st->level[0], pgtable->start_level); + if (ret) + goto free_with_state; + + st->ipa_marker[0].name = "Guest IPA"; + st->ipa_marker[1].start_address = BIT(pgtable->ia_bits); + st->range[0].end = BIT(pgtable->ia_bits); + + st->kvm = kvm; + st->parser_state = (struct pg_state) { + .marker = &st->ipa_marker[0], + .level = -1, + .pg_level = &st->level[0], + .ptdump.range = &st->range[0], + }; + + return st; +free_with_state: + kfree(st); + return NULL; +} + static int kvm_ptdump_guest_show(struct seq_file *m, void *) { - struct kvm *kvm = m->private; + struct kvm_ptdump_guest_state *st = m->private; + struct kvm *kvm = st->kvm; struct kvm_s2_mmu *mmu = &kvm->arch.mmu; - struct pg_state parser_state = {0}; int ret; + st->parser_state.seq = m; + write_lock(&kvm->mmu_lock); - ret = kvm_ptdump_show_common(m, mmu->pgt, &parser_state); + ret = kvm_ptdump_show_common(m, mmu->pgt, &st->parser_state); write_unlock(&kvm->mmu_lock); return ret; @@ -54,22 +172,36 @@ static int kvm_ptdump_guest_show(struct seq_file *m, void *) static int kvm_ptdump_guest_open(struct inode *m, struct file *file) { struct kvm *kvm = m->i_private; + struct kvm_ptdump_guest_state *st; int ret; - if (!kvm_get_kvm_safe(kvm)) - return -ENOENT; + st = kvm_ptdump_parser_init(kvm); + if (!st) + return -ENOMEM; - ret = single_open(file, kvm_ptdump_guest_show, m->i_private); + if (!kvm_get_kvm_safe(kvm)) { + ret = -ENOENT; + goto free_with_state; + } + + ret = single_open(file, kvm_ptdump_guest_show, st); if (ret < 0) - kvm_put_kvm(kvm); + goto free_with_kvm_ref; return ret; +free_with_kvm_ref: + kvm_put_kvm(kvm); +free_with_state: + kfree(st); + return ret; } static int kvm_ptdump_guest_close(struct inode *m, struct file *file) { struct kvm *kvm = m->i_private; + void *st = ((struct seq_file *)file->private_data)->private; + kfree(st); kvm_put_kvm(kvm); return single_release(m, file); } From patchwork Tue Feb 20 15:10:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 203639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp466058dyc; Tue, 20 Feb 2024 07:13:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUYeXLh5nmfCq1osj3vKC9rJCxwhuAFCOvwSQs7YVQgLBTtdUW3RFljNsH0xh+FEClJtwdY09H1eF/LIVtKqfrnpyK6ng== X-Google-Smtp-Source: AGHT+IFhQ0rdrG2IvjSmSoMj4x+C8eTBVbDI0oIteRqnOdnYN+WzvUoN2qP9dao7dyyex/ZNVDtc X-Received: by 2002:aa7:df8c:0:b0:564:9286:c6c1 with SMTP id b12-20020aa7df8c000000b005649286c6c1mr3085094edy.24.1708442022107; Tue, 20 Feb 2024 07:13:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708442022; cv=pass; d=google.com; s=arc-20160816; b=NHkCLcsmJuAPKaUOmIZaE/9zzT/6q+GbdPCuL59L8paIa2xPnG+aAbb/0GKAxwUS08 OoTHorHJ59IobottIGcTU16Q3LK3gGZO+CH4uqb48hT45Nz2WNoBOnEBDaDRhqyeNBGB CE7LyPFEAuI5MBzSsGmEoEhh7c14I7fBa4DdyoAbInwYuanek/VCslD8aoIwjVgrhAp7 L77ew896UPCrxNgG4kNUyB9dbiFLaoKcbsQywEIVjCdrZFeskeHRREA1vRVRaRUmyWf5 RaaWzm364kQyHY9mZLU7x7tIek+okSTDDb9HNtIJNOyxMzK+nsR1uCR9JS0GWM3n1Xrb Gu8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=H7oP8Hepk3ownDnPLORI/cfTnoWlrJNhVmX40NRmmOs=; fh=W/LmMrbzKYjoVmM+ten5VxGBfm7nYCFqha9pJwpgg+I=; b=xG/5okomUPMZeTlYIg9276EHlneymKkvNTsleDv1X73uT8jqmY8RWdtulSbkWYGah9 r0Ra6dGHDuI9McodEb/JjfX3309a0RWByMGCetIouvq1vTWFDlF1yFiC5aWKNQM9RRix WPv8bU7ES5P8gtXYQRk65xNnYP26OEcoTwk/HASi3FXFybDmHWB5dljhWwHR1dVlZb71 0Zhcv72u1BuIX5Vr1h7asedZgfNC0yXhLI1e6qxnJ5zeznAybQhjOi3dT2wFbhzLbbUt 488nIpl89+nMJTjwDoqy8rVYa9fpKTJbySqmrt+dxJ9PQmJiBixNQ0AyEV4U5/rdVW2h 77VQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="SeB/23qB"; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73227-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73227-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e18-20020a50a692000000b0056450f6d502si2581823edc.516.2024.02.20.07.13.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 07:13:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73227-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="SeB/23qB"; arc=pass (i=1 spf=pass spfdomain=flex--sebastianene.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-73227-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73227-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 B84531F22773 for ; Tue, 20 Feb 2024 15:13:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E14F768F3; Tue, 20 Feb 2024 15:11:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SeB/23qB" Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3E4176415 for ; Tue, 20 Feb 2024 15:11:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441909; cv=none; b=rsYbg5IQPaqzKDcw3b/NXH5/sGanjySuM2mawQyHnKS3I8oAhM6AR9qW8b1OvoMTgVn/aUgCLhg3Lku7CizYJzuuJYwuI0sRp/0hDq2xiW0kDI3yGCylb+j8IcWVO2zqL9wnAj7E5eAmjXFLvnwdE7MthzPKZcijOFLJjKkCWvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708441909; c=relaxed/simple; bh=iAbfp5RMm6S0VsTLeL0qLihHKZbBLamOM0a8x66sOYk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qe6wi1L7P14TOowR6ZHzfYQFBE1uN6ixvAblIoTDhH7nh48lQaFivwhytnCMk0dtvUYuziQZ4GTE4s8tDcwDY93RXVpj87Jkm81VlBziWD6F5GaLHzZtMZFwePXpxN+4lCh5Bp6bJs5S53QC312ggDtspky04tHnvW1EGcEaeNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SeB/23qB; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-40f01cf71ceso32331395e9.1 for ; Tue, 20 Feb 2024 07:11:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708441906; x=1709046706; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=H7oP8Hepk3ownDnPLORI/cfTnoWlrJNhVmX40NRmmOs=; b=SeB/23qBiLQHIBwyrSbXj4AWgF3imIC5u4XC3L4VZjuNXwlzggVXLl0n9FvmRH0ALC WJpeQIfqU45qhciXLALfD7O8mwOkM2mQygj1QrTTYNQTtKt6XUSI6tVeocrCZCmMVj4m 1LhJDDTxL+KMmkIG/ndedDTfMdWUuKwgPu15M7ovN/7RPpgXeBwbw8DtoQ7B6ILA7BZE pym8pIgq+9sQKJJK6Dy3A0BMd2vZaHcO+OsOcGRRu+tDuQNmicsHT+wF06hE93UYIi94 irlp7VjGU5l10dAvKXrkA6+JWO2qOlIrEHc0fJgR2DqPOAjF1n0ojaLuwI+Lls5Uiot2 nHzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708441906; x=1709046706; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H7oP8Hepk3ownDnPLORI/cfTnoWlrJNhVmX40NRmmOs=; b=v+IVTmH03VPMLZLsSQLI8/Yyw2V7KRqQ1i92wTBdBonuiBPR35YDj1MiB40jp0yQEk uq8H6/kn6wXHVQqvbDOn/60N95Yu8ANwEgLSLA8RPNpgxhiMeyiblbCdg5/jhZifU1zj ZSm/vUnHWJ2Zj1EsbusBOCNEgFiP25hgRVOSQ1saY+x/taAruLjtWooYoixLiT41qHN8 XILxGwW+Tm//D073SasfZtLGt4L5GRHD+d01/gtw34Yr39CpKD09Qg8IwAD9DHDisOKG n9CWjqV+//S4ajr/bDfR/NplktoRcNbIpiIfgAP/LilBi+Ann1Uq2eDNrMCrhfkBmYFb wwAw== X-Forwarded-Encrypted: i=1; AJvYcCUXQEHhgqJGvHFeO8fw83M4lGOeNWm4zZylUfBbvei6YdmrbcBrz5X1gfcgrreco4hjgu2AM4NPiob4JJZDKz92PZgISvDN+imHHmNx X-Gm-Message-State: AOJu0YwNYNiU2+okfiJkz+JBqNfZt1ikt53UjAZoEUGlimDqOhsQ7tSw Z88VEq+ZRI1ufxNd2TuH/vpuuMAXIF4NU6tk7Yyb+Vg8H75tsS7UDHJkVIQVLDpNH3YXokxEXWj +c0JzDxE1LUQCDL6HNcyfPkpgeA== X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:600c:a:b0:411:ea5e:6142 with SMTP id g10-20020a05600c000a00b00411ea5e6142mr115684wmc.2.1708441906396; Tue, 20 Feb 2024 07:11:46 -0800 (PST) Date: Tue, 20 Feb 2024 15:10:35 +0000 In-Reply-To: <20240220151035.327199-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240220151035.327199-1-sebastianene@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240220151035.327199-7-sebastianene@google.com> Subject: [PATCH v6 6/6] KVM: arm64: Expose guest stage-2 pagetable config to debugfs From: Sebastian Ene To: catalin.marinas@arm.com, gshan@redhat.com, james.morse@arm.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ricarkol@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, Sebastian Ene X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791431301599043548 X-GMAIL-MSGID: 1791431301599043548 Make the start level and the IPA bits properties available in the virtual machine debugfs directory. Make sure that the KVM structure doesn't disappear behind our back and keep a reference to the KVM struct while these files are opened. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/ptdump.c | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index 2c4e0c122d23..a68a22592e97 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -213,8 +213,58 @@ static const struct file_operations kvm_ptdump_guest_fops = { .release = kvm_ptdump_guest_close, }; +static int kvm_pgtable_debugfs_show(struct seq_file *m, void *) +{ + const struct file *file = m->file; + struct kvm_pgtable *pgtable = m->private; + + if (!strcmp(file_dentry(file)->d_iname, "ipa_range")) + seq_printf(m, "%2u\n", pgtable->ia_bits); + else if (!strcmp(file_dentry(file)->d_iname, "stage2_levels")) + seq_printf(m, "%1d\n", pgtable->start_level); + return 0; +} + +static int kvm_pgtable_debugfs_open(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + struct kvm_s2_mmu *mmu; + struct kvm_pgtable *pgtable; + int ret; + + if (!kvm_get_kvm_safe(kvm)) + return -ENOENT; + + mmu = &kvm->arch.mmu; + pgtable = mmu->pgt; + + ret = single_open(file, kvm_pgtable_debugfs_show, pgtable); + if (ret < 0) + kvm_put_kvm(kvm); + return ret; +} + +static int kvm_pgtable_debugfs_close(struct inode *m, struct file *file) +{ + struct kvm *kvm = m->i_private; + + kvm_put_kvm(kvm); + return single_release(m, file); +} + +static const struct file_operations kvm_pgtable_debugfs_fops = { + .open = kvm_pgtable_debugfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = kvm_pgtable_debugfs_close, +}; + void kvm_ptdump_guest_register(struct kvm *kvm) { debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry, kvm, &kvm_ptdump_guest_fops); + debugfs_create_file("ipa_range", 0400, kvm->debugfs_dentry, kvm, + &kvm_pgtable_debugfs_fops); + debugfs_create_file("stage2_levels", 0400, kvm->debugfs_dentry, + kvm, &kvm_pgtable_debugfs_fops); }