Message ID | 20250129172320.950523-8-tabba@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B20FDC0218D for <linux-mm@archiver.kernel.org>; Wed, 29 Jan 2025 17:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5664A28025C; Wed, 29 Jan 2025 12:23:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51635280067; Wed, 29 Jan 2025 12:23:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 342C828025C; Wed, 29 Jan 2025 12:23:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0FE33280067 for <linux-mm@kvack.org>; Wed, 29 Jan 2025 12:23:41 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C8891160F84 for <linux-mm@kvack.org>; Wed, 29 Jan 2025 17:23:40 +0000 (UTC) X-FDA: 83061161400.13.E0FE7AA Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf20.hostedemail.com (Postfix) with ESMTP id F05C11C0019 for <linux-mm@kvack.org>; Wed, 29 Jan 2025 17:23:38 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=hG7xCVG5; spf=pass (imf20.hostedemail.com: domain of 3GWSaZwUKCI4Bsttsy66y3w.u64305CF-442Dsu2.69y@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3GWSaZwUKCI4Bsttsy66y3w.u64305CF-442Dsu2.69y@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738171419; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=clAA2pQ0aAsHHtJcPdsprveMf7sd3Qr2fHuajtMaEDo=; b=wsB4KrWNLX0HkirYgcvzO2RPJZ0Jx2QuYbpjWGyyAHdbgQL4iHBRvjf5TUqL9HsF2HqXcJ 7zJ9/RwocVQoSni8dSqbUdWBO3BnFxp2Z1HE9Kb+AxgtUVEY6rJyHJvC92Vk6HTGC54lKT weg4c31oxNeXuhdUOd+5b8K7PwVfLQY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=hG7xCVG5; spf=pass (imf20.hostedemail.com: domain of 3GWSaZwUKCI4Bsttsy66y3w.u64305CF-442Dsu2.69y@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3GWSaZwUKCI4Bsttsy66y3w.u64305CF-442Dsu2.69y@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738171419; a=rsa-sha256; cv=none; b=7lRn5eoWCtHGafXtDb3V7aYVwRPsoWib9V1geVVl/SVXjvHigDyGItquoxzR2QDv7KS6Yt EWQ75Ar3JqsLK1CeEyBgkb/B0xeoj0pz//NYImmmk32rvFfiKq93TP9phCHrjkYq4QRzTX rRa3PKwrsf6C+o5LsSwdkEjYkKIDy8Y= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4388eee7073so4788955e9.0 for <linux-mm@kvack.org>; Wed, 29 Jan 2025 09:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738171417; x=1738776217; darn=kvack.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=clAA2pQ0aAsHHtJcPdsprveMf7sd3Qr2fHuajtMaEDo=; b=hG7xCVG5KzbGS1+zuDxth/vlvPjeWOAy3khVm1AvsHg+9JDRa4wtRUvM+qjPIXi38u 88wpmECFETtzuk6I0Owaz6OSToQNwWWItE+g8v5MUkzpLQlRBfX39rNFmc39RYzNVLUI 6PElgV9HxAvY33pnfsdw3OwbC9QoM/awCgF9Lu0FZ1T5vNtXreKjb2O6DPf9vMoAyQ/C uA8pbp45mW54KgR+mN2Bo7V6QvHRJlWgdjEBNiR++IIrLmuYjfruAvjGL0xooD3BB+Nl d4uaWBvdcL/zwibaWQjXKG1QW+mtGP03P9mDYinzOySmdxMvLUj2c4QuiAyUGfMn8DPT aYpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738171417; x=1738776217; 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=clAA2pQ0aAsHHtJcPdsprveMf7sd3Qr2fHuajtMaEDo=; b=mNLxrde7KWRYS3y64tsAuj08fqi1cvBM+yfaVY2k9X6GmqbI0dF+k1Jx4Te0IzD7ER wxnfRmshZqEisA4OskoE2/AJRtavkfx6BrClKlDEjQJXqtW/VOJLtdwv5TgG7wH7d9rB 7gXumagMjHvUBxYVsTbRbis8fhrfxrkhKov9l+jhvBp+bPKipcHNu3gnGKW3dGNOk7yF tK0u45kODf7NVNa36icQRBkLvdPY8No8hEksen1iXaWqILusyw2OH1YbqujdkD0IjNWi dLqX14IdXqsqlaUOLSwTrARqmn+5dvP5/4AuPtkYKw/fY5y96g0YJk4nlhVDY3lHwNRx ZGPw== X-Forwarded-Encrypted: i=1; AJvYcCWMuD4eDFVHg6jMM/HX18FXTSHWh+RftuUaH6X4aR4VJqJnnprd4y1LlFL5/EdxwXemvRLAKvkxGA==@kvack.org X-Gm-Message-State: AOJu0YyHTwHayKIPe+V+e6fIPF/tSXavHTGox8NKkO6ZbtQUE3gAGdUu d24GVQVl+uaBjJGUsyyhKmw9eGO/3h/VN073zvBwlzGzgfWy1uVdoJQNCwk7zuH5PM2EJGMqqg= = X-Google-Smtp-Source: AGHT+IH4Z/w8m7ect4Xjx7d6nFW4rotWrjkyMgHYG1tUIFYfo/owBhkDUsni5QfNbmeYmc7O93FGA8qkJQ== X-Received: from wmd22.prod.google.com ([2002:a05:600c:6056:b0:435:dde5:2c3b]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:b8d:b0:436:1b77:b5aa with SMTP id 5b1f17b1804b1-438e15e8307mr1177165e9.8.1738171417631; Wed, 29 Jan 2025 09:23:37 -0800 (PST) Date: Wed, 29 Jan 2025 17:23:16 +0000 In-Reply-To: <20250129172320.950523-1-tabba@google.com> Mime-Version: 1.0 References: <20250129172320.950523-1-tabba@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250129172320.950523-8-tabba@google.com> Subject: [RFC PATCH v2 07/11] KVM: arm64: Refactor user_mem_abort() calculation of force_pte From: Fuad Tabba <tabba@google.com> To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, jthoughton@google.com, tabba@google.com Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: F05C11C0019 X-Stat-Signature: 54ugbzask7itwztm9s6iju3ha64t75qe X-HE-Tag: 1738171418-258726 X-HE-Meta: U2FsdGVkX1/qUv6BA7XAyR0tjr8h2jkTIoERBKUJgYLQcRRVJNB1yUmKsZHKSOwEKOFF7/6QDxX+rBhqYoEZAt3vXFHiPQK7gEGQtSPooOCa6zLAo1tVVDe24D1vwLzByccYq85XdO+TD0F+rEjEPpfMJXbzdjB5bhHhBqUz0wym7VieIjVo8CzkrJfMSStJeZBm1e0Lpkk+fm+8FfNcgabTAdXg1VlAlrYo2AX2xYJkGMCOGG1hOseE2g2Xm7Mn6glhDFH3T2X2RzTFZ9fHY/GdDXhSJxvx0PZH4xmjJUq9x9ecZVmJIhHyPi0kVvrr8RmYNGQ+QwdhCL7V4QOqMxaD3QGjyc+Okx0/6KzP55r60FEH1w/MWdILhiJXRTWLc6Wf7CV2k1ysCcQLdGiVn5n+AyAhfCxnYZI5omGSMLvJ5lFi/awPzqDOnqvDURoqrc4OgIn49otz9AC5dDpBoEcp/UwOUBWRyAq2iTTttjqNhlmDffsXy1M7LUtgbX2k9tNP1Qjno3vYqLZwsvtQzcmAqLm1vWO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P2bXlm7LvbhW8izKChJC3LgYB4QcisJfGkXkTuOSDCMnWw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
KVM: Mapping guest_memfd backed memory at the host for software protected VMs
|
expand
|
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index c9d46ad57e52..1ec362d0d093 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1436,7 +1436,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, bool fault_is_perm) { int ret = 0; - bool write_fault, writable, force_pte = false; + bool write_fault, writable; bool exec_fault, mte_allowed; bool device = false, vfio_allow_any_uc = false; unsigned long mmu_seq; @@ -1448,6 +1448,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, gfn_t gfn; kvm_pfn_t pfn; bool logging_active = memslot_is_logging(memslot); + bool force_pte = logging_active; long vma_pagesize, fault_granule; enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt; @@ -1493,12 +1494,13 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, * logging_active is guaranteed to never be true for VM_PFNMAP * memslots. */ - if (logging_active) { - force_pte = true; + if (WARN_ON_ONCE(logging_active && (vma->vm_flags & VM_PFNMAP))) + return -EFAULT; + + if (force_pte) vma_shift = PAGE_SHIFT; - } else { + else vma_shift = get_vma_page_shift(vma, hva); - } switch (vma_shift) { #ifndef __PAGETABLE_PMD_FOLDED
To simplify the code and to make the assumptions clearer, refactor user_mem_abort() by immediately setting force_pte to true if logging_active is true. Also, add a check to ensure that the assumption that logging_active is guaranteed to never be true for VM_PFNMAP memslot is true. Signed-off-by: Fuad Tabba <tabba@google.com> --- arch/arm64/kvm/mmu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)