Message ID | 20250117163001.2326672-14-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 13151C02183 for <linux-mm@archiver.kernel.org>; Fri, 17 Jan 2025 16:30:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69C186B00A5; Fri, 17 Jan 2025 11:30:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 626146B00A8; Fri, 17 Jan 2025 11:30:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44B006B00A7; Fri, 17 Jan 2025 11:30:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 230E96B00A5 for <linux-mm@kvack.org>; Fri, 17 Jan 2025 11:30:35 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D027512052D for <linux-mm@kvack.org>; Fri, 17 Jan 2025 16:30:34 +0000 (UTC) X-FDA: 83017481988.24.618E9CD Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf11.hostedemail.com (Postfix) with ESMTP id D2A9640010 for <linux-mm@kvack.org>; Fri, 17 Jan 2025 16:30:32 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1n4haQ5I; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3p4WKZwUKCCAP6776CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3p4WKZwUKCCAP6776CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--tabba.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737131433; a=rsa-sha256; cv=none; b=yXWEaWkel79evm+5briwbpetsNrfFBHvKsHxU0ONng/EGoI84XtxCcCQppJcCIX6VnKITo URUy/PWKQSh83M+dobw+KLvVJtNxUQsOYvWrrqjerd+uPzK3EgPPsLbSF4i1RH4fYI1GUB KFvRYra/OM7zvkKrZqAiOPSFQnAbbjE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1n4haQ5I; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3p4WKZwUKCCAP6776CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3p4WKZwUKCCAP6776CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--tabba.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737131433; 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=3HB24ys9olZtoFbzLvLFGPKqOLdaE1YgibZ0bUHAkc0=; b=eXKWOT3HlewZ06w+FrZxstYlG8eQNlVoGVohaxEPEi5In7Qb0P2IDX76B0/48ziI7/Mmyt lxYhPTD7CAywvfvsfAc/oq+LemlQK24zM9QyUpniwVaQC2up3cNVUJ1Xc4KQvvTvt9NKZs LuG/QGWelj/iH6SLC9bsR0emL7D9bxU= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4361d4e8359so17265955e9.3 for <linux-mm@kvack.org>; Fri, 17 Jan 2025 08:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737131431; x=1737736231; 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=3HB24ys9olZtoFbzLvLFGPKqOLdaE1YgibZ0bUHAkc0=; b=1n4haQ5IQSSKjY0PHgw4KJ5PBzA8tdcgCS1vdPI15Mmd4u8bEK67R0tU6ON83UCkk3 kwi/5jkZQtWJ6ei8s9IQAFlacur4X73NdiR2VBQS455ql4iuiq3NvnFHnQFt1aNIlD+h VjMd9wu/Ailbk+wPHlU1RDEQw7WLebT2vAYKQ4GVLdA6HbH68Zz4QeiuqFoqa5WKusMw snd4z2PyxfqpURQpNzD4H9sLtugnsNL7nblgK2KYseDCThTRsHKTxph6Y39Acuidk/vP kH6k5UFLhUujc6MfT3OdPUyfWpFWGj7J7R0tnQjAuk5kP3NrIYgPdCP0BNNye3j8LZ4p C3Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737131431; x=1737736231; 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=3HB24ys9olZtoFbzLvLFGPKqOLdaE1YgibZ0bUHAkc0=; b=AojbdLRpdmixQbHBQASpaZlVTVuzRLFl5sJh8sV0b+rMvUsA6PViWHpHdSqoyNuWZC KOl4JZorCzhQ5d6Y/Dxf8aKXzt9ZN0bx6FjNb7Px7EWTYzNAe2rqAGwp7GUn9a6lfyk3 RSgscFs9a+/Ufy63SoNr0W1DXg1MVYkGN5b3WHYZOwKuKZ3IhX8Nj06H/prLQnwn/0fl cRmemcQwGcLkw+IU7x9ddmc5U0E7S1HVaDBUgSrVjwijXU/kO8naDwR5/7pQisf+GkJv 3MQfeStR2qGTmqUsGUu+BnJnFnl253//On05DOyusj8CgqCIfjsBUvq2Q1nymsNs+b/t qM+w== X-Forwarded-Encrypted: i=1; AJvYcCUVDjF6fSbSkS0Mo7Ah4k7rad+oewl/iTRTcUuWy8B79YzlHKkWyITVYK3holqvKqzt3s0G/ILwIA==@kvack.org X-Gm-Message-State: AOJu0YxxldozXaTetEeJuWA4KuAJs5xflHZ0CPHn6iUvcPq2r3OEWRlH DBabkcvEN94Wrpt09iMTRRgLy2t0PBpsrs9gK+fdSnO2eCPbVjp3jLrl0YFm+T4Ns7F7R0/Feg= = X-Google-Smtp-Source: AGHT+IGXpNihxZ+huy1r8urGkN90UYrt/W0V/muXsXaxH9j2ly0sDzEqcBhbyJ7KDudMWMW1llJmatLXLw== X-Received: from wmsd5.prod.google.com ([2002:a05:600c:3ac5:b0:436:e660:a347]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3ba7:b0:435:21a1:b109 with SMTP id 5b1f17b1804b1-438913bdcc7mr32672145e9.2.1737131431466; Fri, 17 Jan 2025 08:30:31 -0800 (PST) Date: Fri, 17 Jan 2025 16:29:59 +0000 In-Reply-To: <20250117163001.2326672-1-tabba@google.com> Mime-Version: 1.0 References: <20250117163001.2326672-1-tabba@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117163001.2326672-14-tabba@google.com> Subject: [RFC PATCH v5 13/15] 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: rspam01 X-Rspamd-Queue-Id: D2A9640010 X-Stat-Signature: 4kq1t1xioxqk47hzaz5ymwqhtrguy8ug X-HE-Tag: 1737131432-307007 X-HE-Meta: U2FsdGVkX1+8ulA1DuipF1fC5VbDaWyPEwbFyMfWWcIdO5/rhNVycctIkHCM6XJlVo3qSzEyJzhEH3DmNX5QkcLuSmMCnczGv2gAi9gusxBTyoSs1B/dhP8xKoisW+pCg2GqvmYp8bECcxlC2SSnQnl2B+QaQWARKufYH4FIXZd5Q+Amgc71N3KtZfrq5DSlsEgJJxY9y4UcuoWZYaV0OERGULSqcOeInu6yaJsVaLKEWYoaneHWGiMi+gF1tWVjxsCfSW9KxmycPNxzWDGtto1KNTDHFASi/a1DZVg0EhvdaFrZh93DPgiYEsfMfUq0CuB8V3sIwU94g2ZRXFc/l7PGdsd8iIm65TPigCYjPwjEWJx7KV6MQ7TxbRMbVzE31+7tyAVlatOYLI+VmKKc7Qx7seGxY/QvUQbDS6VDIWY6hc8sHTAOuDmHekCQws7H4g9MH7mLcSPKPQhazmiK7gutK6R2FFucF0FP1bcc5dLm6Q+T/WknEfou6xf8mOhZLpOVSI90oz+k9YXJU52eSWc0QgiR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82PRQ0aedkl1W1AIC/HB72qLgEGsKO/cA== 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: Restricted mapping of guest_memfd at the host and arm64 support
|
expand
|
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 342a9bd3848f..9b1921c1a1a0 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1440,7 +1440,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; @@ -1452,6 +1452,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; @@ -1497,12 +1498,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(-)